r/cpp • • Jan 09 '19

Dear /r/cpp

Sonny from Codecademy here. Last month (Dec 3rd), we launched 4 modules of our first ever Learn C++ course!

https://www.codecademy.com/learn/learn-c-plus-plus

  1. Hello World

  2. Variables

  3. Conditionals & Logic

  4. Loops

And as of this morning, 87,504 learners around the world have started the course!

I'm extremely happy and proud of this because C++ was my first language that was taught in my CS class and 10 years later, I got the chance to work with Dr. Stroustrup and share something that I love with the world.

However, as my teammate Mariel and I about to author the next few modules, I couldn't help but feel that there can still be a lot of improvements made in the first 4 modules. I'm wondering if anyone has taken or is interesting in taking this course and give me some feedback and ways it can improve.

There are also a few things I'm still conflicted on:

  • Should I include `return 0;` in the very first lesson?

  • Where is the perfect place to introduce `using namespace std;`?

  • Where to introduce the different types of errors and debugging?

Any feedback would be highly appreciated! And happy to mail out some Codecademy tees and Pro memberships too!

17 Upvotes

50 comments sorted by

View all comments

4

u/MontagFTB Adobe Source Libraries | stlab Contributor Jan 09 '19 edited Jan 09 '19

Should I include return 0; in the very first lesson?

You do not need to return from main and the program is still well-formed. (main is the only function that returns a value for which this is true.)

If you do decide to keep the return expression, I would suggest using EXIT_SUCCESS as it is considerably easier for a beginner to understand than an integer value.

5

u/JonKalb CppCon | cpp.training Jan 09 '19

When teaching a complicated subject to beginners, it is best to avoid special cases and exceptions to general rules. If possible, avoid the special cases and postpone discussion of exceptions to general rules until after beginners are comfortable with general cases. It is also best to postpone discussion of distracting details.

The special rules about main() (that it must have a return type, which must be int, that, even though it has a return type, it need not have a return statement, that if it doesn't have a return statement the system will provide a returned value) are all minor not-first-day-of-learning issues.

The fact that OS's expect programs to return zero to indicate success and non-zero to indicate errors is a distracting detail that is also unworthy of mentioning in a first class in C++ programming.

In keeping with the best teaching practices, it would be best to not have to mention any of these special rules/exceptions or distracting details to beginners. Unfortunately, main() is the one function that every program must contain. In order to not have to mention any of the special rules, you will need to have your example main() return a value and if you return zero, you will need to explain the semantics of that value.

So I agree with MontagFTB. Ending your program with

return EXIT_SUCCESS; // Tell OS we were successful.

and the explanation that we need to signal to the OS that our application executed successfully, minimizes the distractions and avoids a lot of explanations that are simply not important to beginners.

What MontagFTB didn't point out is that you will also need to have

#include <cstdlib>

because EXIT_SUCCESS is defined in cstdlib.

Note that there is hope for this situation. It is possible that future standards will allow main() to return void, which will significantly simplify "hello world" level instruction.