User forums > General (but related to Code::Blocks)

Too dumb to get started?

<< < (2/9) > >>

Newbie0815:
well, that tutorial at cpluplus.com is quite nice
I actually got a few steps further than usual, still I´m getting to the same point
example:
in the chapter control structures there is a paragraph about "switch" which has an exact equivalent in "if-else"
both do the exact same thing and I really don´t get, for what shall a real bloody newbie learn 2 different things which do the exact same?

I can understand, there are differences for advanced users, I´m sure there are things which can be done easier or faster by "switch" than by "if-else", or something like that, but for someone like me who wants to learn from scratch, when I find 2 different ways to do the exact same, I start reading the chapter until I find out it wasn´t even neccessary to learn this sh*t, because I already know a much easier way to do the same

Can´t a beginners tutorial be restricted to the easiest way to do something?
Why would it be important to a newbie, whether his very first miniature program requires 10 times more processing power? Whats the fortune of learning about the difference between local and global variables while the entire program I´m writing requires a total of 2 variables
Why should I learn how to pass variables through functions, while my entire experience is restricted to printing "Hello World!" to the screen?"
Hell I´m not writing a new OS as my first program
I can find several different ways to get from paris to rome, but if I don´t have a map and no clue where rome is located, why should I learn the route by car and by plane at same time? My goal is to get there and unless I know already how to get there by plane, I´m not interested at all in the fortunes of getting there by car, for a firsttimer the easiest explanation is the best, regardeless whether or not thats the best way to do it for a pro

However, these things make me bypass the rest of a chapter, furthermore makes me suspicious of several further duplicated ways to do the same, making me skip more and more, just to grab the easy way, which obvioulsy leads to the problem, I don´t get a word anymore in following chapters, because the author of the tutorial expects that I have learned ALL options to do the same thing, rather than the easiest one

sethjackson:
Well a switch statement is like an if else-if. It is (I have been told) faster, and sometimes more efficient to use a switch.

Here is an example.


--- Code: (cpp) ---int main()
{
    int a = 0;

    if (a == 0)
        //....

    else if (a == 1)
        //....

    else if (a == 2)
        //....

    else if (a == 3)
       //....
   
    else
        //....

    return 0;
}

--- End code ---


--- Code: (cpp) ---int main()
{
    int a = 0;

    switch (a)
    {
        case 1:
            //....
        break;

        case 2:
            //....
        break;

        case 3:
            //....
        break;

        default:
            //....
        break;         
    }

    return 0;
}

--- End code ---

Do you follow that?

EDIT:

Sometimes the easiest way to do something isn't the easiest way to do something else. ;)

Like  10 * 3 = 30. Or 10 + 10 + 10 = 30. Ok not a good example, but I think you get the idea. :) 

Newbie0815:
of course I get the idea, if I know how to do something and then I discover an easier way to do it, great, I´d love to learn the easier way, but as long as I don´t know ANY way to do something, why should I learn 2 differnt ways simultanous? Thats twice the work on start, maybe helpful later on when it comes to complex programs, but on start its boring stuff, taking twice as long to learn the basics and at least for me, investing so many hours in learning a dozen different ways to do the SAME thing doesn´t show much progress towards the general goal and the slower the progress, the more often the idea pops into my mind, at THIS speed I won´t get anywhere within my lifetime

killerbot:
Well I have to disagree here. If you want to program in c++ you have to know the language !!!
As the above raised example of switch and if/else. You can NEARLY do the same thing with both, but here's such thing as readability and maintenance of code. Code which is hard to read is BAD code.

Excessive if/else can make code hard to read and understand where in several situations the switch is much easer to read and understand. And for simple tests an if/else is better to read then a switch. The number of language constructs in c++ are not that many.

Next what's easy, what's not.
Character arrays are easy :
  char szTest[] = "This is a test".
Or maybe they are not, concatenation, terminating zero, size issues, allocation, deallocation. Headaches, memor leaks, crashes, ...
Well then STL's string class is easy, no need to worry about those allocation and size problems (well there's the performance level), but hey let's have a look at that string class declaration. Damn that's not so easy anymore : trait's , allocators, templates. Huh, well duh.

Programming in c++ should be taken seriously, I have seen to much stupid, erronous and awfull code because people didn't know the (entire) language.

The same with loops : while() , do while(), for () : many times you can convert one to the other, but sometimes one is much clearer to use in certain circumstances.

It's overtime one get's the feeling which constructs are to be used when and where.

Hey let's even take it more simple :
  int x = 0;
  x = x +5;
    OR
 x += 5;
Well why two ways, come on, why, why, why ? Performance, the latter one is faster. But we need the first one, yes we do : as in : x = y +5;

Ruling out options in the beginning is not wise, get to know all your cards and you will play a better game.

[EDIT] there are probably tutorials how work by means of examples and add language constructs as they go. It's just how the "theory" and "practice" is divided. When I learned driving I first had to learn all traffic signs and rules. And to be honest during my first drive I surely did not came across all those signs. ;-)

marfig:
You realy cannot learn C++ programming based on tutorials only. You will need to buy a book eventually.

Tutorials make for a good startup. However they have to be generalistic in nature (they wouldn't be tutorials otherwise). The concepts therein are presented lightly and the examples hardly ever have much meaning in real life computing. They are poweful tools though, in the sense they provide an understanding of some of the language features; what are they and how they are used. But, again, they do this at the expense of depthness.

Books, on the other hand, have a lot more space to go into depth about the language features. And that is probably what you are missing. I strongly suggest you buy either Accelerated C++ or C++ Primer.

There is another problem with tutorials. Most of them are amateurish. There are fine tutorials out there, but there are others that do a very bad job at teaching C++. In fact they will only add to the confusion (I guess this is true of some books too). The preciseness of language choices when writing tutorials or books is fundamental when one wants to teach a programming language like C++. There is a big difference between a pointer to an array and an array of pointers, and yet many authors chose to confuse readers by choosing terms like "a pointer array", which can mean both or none at all. Once C++ is understood this choice is no longer a problem. We know what it means from the context surrounding it, but for someone learning the language, the author didn't provide him a good service. Another example is not applying correctly words like "definition", "initialization", "declaration".

Learning C++ can be a frustrating experience already without these problems adding to it. What I strongly suggest you is to follow a few guidelines:

- Concentrate on the programming language first. Learn the language. Get yourself one of those two books above (my personal favorite is C++ Primer) and read them carefully. Experiment a lot. Even if what is being explained to you seems obvious, write the code to prove what the book is saying nonetheless. Read, code, read, code... ad aeternum.

- Write code that intentionally explores the bad practices the book is telling you not to use. See what kind of compilation errors you get. Try to remember them for the future. More important, try to understand why it is a bad practice. For example, when learning about dynamic memory and memory leaks, purposedly provoke memory leaks in your code. Write cout statements inside the object destructor to see if it was ran or not and when it was ran. Explore everything! What you should do and what you shouldn't do. Half of the way to understand C++ is to understand about what you shouldn't do with C++.

- Learn your debugger. This is probably one of the most important things. You absolutely, utterly, without any doubt whatsoever, need to learn how to debug. You are not going anywhere if you don't learn how to debug. It's not complicated, you need to learn mostly about breakpoints and watches. At least for now.

- Learn your debugger. I've put it here again to stress this out ;)

- Do not, I repeat, do not try to write a complete program without having gone through the book at least once. This is important because most people try to put the wagon in front of the horses, only to find out later they they will need to code a feature they haven't learned about yet. Then they go on to read hastily about it, implement it in some bad way, and not gain a clear, in depth, knowledge of it. The reasult is that they think they know how to use it, when in fact, more often then not, they have only scratched the surface. Do not try to write a full program before you are done with the book at least once.

- Be patient and be veeeery slow. Learn everything slow. Be sluggish in your learning of C++. You are not going anywhere and the language will not puff away. Understand that it takes around 2 years to be proficient in C++ and maybe a couple more to feel totally at ease with it. The important thing, what you should concentrate most is understanding that first you need to know what the language provides and how it provides it (C++ features and syntax) and only then you should concentrate on how to effectively use those features. Don't plan your learning process, don't set yourself deadlines. Be patient, slow and sluggish.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version