John A 1,896 Vampirical Lurker Team Colleague

The internet gives us a wealth of information, and programming is no exception. You can literally find learn about any language just through a broadband internet connection. And since 90% of the tutorials out there are free, what better way to learn programming than if it doesn't cost us a penny? Unfortunately, many programming newbies do not realize the hidden gotchas behind using these tutorials. Too many simply do not teach us what we should not be doing, or worse yet, not teaching us what we should be doing.

Let me give some C/C++ examples, since that is the language I write software in. Look through the majority of the "starting C/C++" tutorials out there. How many actually teach you that:

  • void main is wrong
  • fflush(stdin) is undefined behaviour
  • gets is unbuffered
  • scanf() and cin >> leave trailing newlines in the input buffer

And the list goes on. Now, some of you may be thinking, "why the heck does a newbie need to know that?" Well, so that when they do encounter bad code that teaches horrid practices, they know not to use it. There are also tons of articles out there that outline the problems mentioned above, but how likely is it that a newbie is going to read that?

Perhaps a better method would be to teach safest methods, even though a bit more complicated, and then introduce other practices once the user knows how to handle them. Like teaching usage of fgets() and getline() instead of cin >> and scanf(). It's harder, yes. But the typical problem is this: a user learns the easy method by using one of the aforementioned techniques that leaves a newline in the input buffer. That's all fine until they realize that they need to input a string that has a space in it.

A smart newbie might quickly Google it, see that getline() reads an entire line, inserts it into his/her program, and then wonder why it doesn't work. That's when the friendly folk at DaniWeb has to help them out. ;)

This problem isn't isolated in online tutorials. There are horrible university teachers that teach us crap too, and there are books that use incorrect practices. Heck, even Microsoft's MSDN uses void main in all their console examples!

Regardless, it would be nice to see fresh new "Starting C/C++" tutorials that explain techniques that can be used in the future too, not simple makeshift code that will break the minute you try to use it in a real-life application. Sure, it may not be popular among newbies, but I say "no pain, no gain". Programming isn't going to be easy, so you might as well get used to it.