[C++] Tutorial in progress

Started by
24 comments, last by ToohrVyk 16 years, 9 months ago
I am currently writing a (free, online) C++ tutorial. The first three chapters are here. More will follow shortly. EDIT (08/07/07) The bulk of chapter 3 is online. Message to advanced C++ users of the forums: The philosophy that I ascribe to is explaining not how the language tools (functions, objects) can be used to accomplish things, but rather how they are used to apply the Once, Twice, Refactor principle. I also choose to introduce SC++L and boost concepts by example, before mentioning their C-legacy counterparts. I intentionally restrict the scope of my statements (for instance, saying that a function must be defined before it's used) until I have presented enough concepts to add more nuances (the existence of forward declarations). However, if you notice details that are outright wrong, or confusing wordings, feel free to PM me or reply to this thread. [Edited by - ToohrVyk on July 8, 2007 4:16:09 PM]
Advertisement
An admirable task, and although you certainly go for the throat (bringing up undefined behaviour early etc) and try to teach good practises from the beginning, while I read it I couldn't help feeling that a "non-programmer" would be slightly lost in parts of this tutorial.

There is a very delicate balance between language a non-programmer will and won't understand. I mean when I was starting out I remember finding it hard at times to follow even the simplest tutorials.

That said I wish I could point you at specific pieces of your tutorial which give me this impression, but I can't. I just feels a little "too technical", which IMO is unfortunately due to the nature of the language itself. Any other article which doesn't address this isn't doing the complex nature of the language justice. Another reason why C++ isn't highly recommended as a beginning language I suppose. (no chance you would put a reference to this fact in your tutorial? [grin])

On a slightly different note, I would highly recommend you include a section about dealing with errors at the end of each chapter. Many books assume the reader will not make typing errors trying out the code. How many times have we seen someone who cannot compile their first program because they mistyped std::endl?

Think of common mistakes (missing semicolons, missing parentheses, std:string) and try explain the errors the compiler comes out with. Since you are making a website, you may find it easier to simply include a link to "dealing with common errors" rather than detailing them inline.

When I started out I don't remember ever seeing a book that tried to explain the meaning behind the error messages. Although you have already included one or two compiler errors they aren't the ones a new programmer would typically have to deal with. Even just explaining that the error message includes an error code which can be used to google the error source would be a good idea.
The "frequent errors" section already existed in the french version draft of the tutorial. I'll make sure to include something similar, though possibly (as you suggested) not inline. Chapter 4 sounds like a good place for compiler errors and debugging [smile]

As for mentioning that C++ is not adapted to beginners... no need to scare the readers: if they don't gather that fact from the concepts presented in the tutorial, I would say it's their problem [grin] you're right that the concepts are indeed quite technical, though, but sadly that's what they are—feel free to mention any unnecessary technical, though.
I only looked over the first chapter briefly but It looks like a great start for C++.Also liked how you explained concepts with graphics and such.
I'm sure it will be a great resource for C++ beginners.
Keep it up!
I like it :)

But I found a few issues. I havn't read all of it so I could have missed something :)

Your main function doesn't return anything in every example. Also I would write something about datatypes before you start talking about references.

Some questions a beginner might ask him/her self:

- std::string, what do the colons mean?
- You're using spaces and tabs, when should I use a space and when should I use a tab.

Suggestion: Explain how to deal with errors and warnings. When I just started programming, I never actually "read" the error. It was more like: "oh my god, an error, what now?" That's a common mistake made by beginners. They know they have an error but they just don't know how to fix it because they're not reading it right.

I would also write something about the usage of google. "How does one convert a string to an integer?" Write something about how to use google right.

Good luck :)
Quote:Original post by WalterTamboer
Your main function doesn't return anything in every example.


This is idiomatic in C++, as an implicit return 0; is added at the end of the function.

Quote:Also I would write something about datatypes before you start talking about references.


Well, references are independent of data types, and data types in themselves are an extremely complex subject (basic types, arrays, pointers, classes, class templates, typedefs) ... since I had to explain that auto variable definitions create a value, I felt that it would be correct to introduce references (which don't create a value) there as well.

Quote:
- std::string, what do the colons mean?
- You're using spaces and tabs, when should I use a space and when should I use a tab.


Excellent suggestions, thank you!

Quote:I would also write something about the usage of google. "How does one convert a string to an integer?" Write something about how to use google right.


boost::lexical_cast<std::string>(i); will be in the tutorial [smile] I'll make sure to add explanations about how to get help.


Quote:Original post by ToohrVyk

This is idiomatic in C++, as an implicit return 0; is added at the end of the function.


You don't know that as a beginner :)

Quote:Well, references are independent of data types, and data types in themselves are an extremely complex subject (basic types, arrays, pointers, classes, class templates, typedefs) ... since I had to explain that auto variable definitions create a value, I felt that it would be correct to introduce references (which don't create a value) there as well.


Uhm... You're right. I'm with you.
Quote:Original post by WalterTamboer
Quote:Original post by ToohrVyk

This is idiomatic in C++, as an implicit return 0; is added at the end of the function.


You don't know that as a beginner :)


Quote:Chapter 2, Section 3.3: "Return Values"
If a function is defined as returning a value of a certain type, but no return encountered when executing the function, undefined behaviour occurs. Compilers often generate a warning about the absence of a return statement. The only exception is the main function: if the return statement is missing, the function will act as if a return 0; statement was present.


[wink]
Quote:Chapter 2, Section 3.3: "Return Values"
If a function is defined as returning a value of a certain type, but no return encountered when executing the function, undefined behaviour occurs. Compilers often generate a warning about the absence of a return statement. The only exception is the main function: if the return statement is missing, the function will act as if a return 0; statement was present.


I'll shut up now [wink]
Very detailed tutorials. I wish they had of been around when i first learned C++.
Game Development Tutorials, a few good game development tutorials located on my site.

This topic is closed to new replies.

Advertisement