r/cpp_questions • • Feb 13 '22

OPEN Damn learncpp.com is AWESOME!!!!

Title says it all. I am learning C++ on such a deeper level from the usual youtube videos.

113 Upvotes

19 comments sorted by

View all comments

3

u/alfps Feb 14 '22

The tutorial stands out as high quality.

Below I comment on the few things that are not, as far as I read (or skimmed) the tutorial.


Part 0.7.

The first statement that I found a bit dubious, after a lot of excellent text and illustrations:

❞ Q: Can I use a command-line compiler (e.g. g++ on Linux)?

Yes, but we don’t recommend it for beginners

Most students who try it find the command line much more convenient than using an IDE, and get a much better understanding of the tools usage. An IDE is designed for large multi-file projects that are the opposite of what a beginner does; it hides the tools usage; and it presents additional obstacles of its own, such as Visual Studio's "precompiled headers" (which are on by default, with non-standard perplexing preprocessor behavior). Happily this tutorial emphasizes that one should turn off "precompiled headers" in a Visual Studio project, although without mentioning the non-standard behavior.

Another nit: Microsoft's Windows Terminal application should have been mentioned and recommended, and there should be a recommendation to make it the default console window handler. Windows as a programming environment is difficult enough without having to struggle with the limited and, let's face it, ugly, classic console windows. Windows Terminal really helps.


Part 0.8.

❞ Q: When executing a program, the console window blinks and then closes immediately.

There's a recommendation to introduce a "stop at the end" statement in the program.

This is only a problem when using an IDE. A good solution is to find out how to run a program from the particular IDE, so that the program's console window persists when the program's finished. For example, in Visual Studio use Ctrl+F5.

A "stop at the end" statement is just ungoodness: no advantage, but adds some problems.

On the positive side this part mentions that an anti-virus may interfere with program execution. That's a very common problem for beginners and it's the first time I see it covered in a tutorial. Very good.

There's also discussion of other common practical problems, and that's very good (and also uncommon in tutorials).


Part 0.10

Terminology: talks about "compiler extensions". But what's discussed are language extensions, not compiler extensions.


Part 1.1

This text, introducing statements, is fine.

But I miss in the preceding discussion mention of tabs versus spaces (tabs have problems, use spaces), and discussion of using namespace std;, which a student is bound to encounter in examples on the net and in books.

The tutorial apparently doesn't use using namespace std; and that's a valid approach (that also incidentally steers clear of controversy), but a student needs to know.


Part 1.2

Discusses commenting. In the section about commenting out code I miss discussion of the possible problems with /* comments for that, and the not uncommon idiomatic solution of #if 0.


Part 1.3

Discusses objects and variables. The first tutorial I've seen that gets the C++ notion of "object" correct.

Problem with the terminology discussion. The main problem is not that "object" in other contexts can refer to functions, as pointed out here. Rather, the main confusion is with "object" in the OO sense as instance of a class, which is the meaning students encounter in e.g. Java and C#. I had expected that to be mentioned. It isn't.


Part 1.4

About assignments and initialization. This is the first error I saw in the tutorial:

❞ Unfortunately, direct initialization can’t be used for all types of initialization (such as initializing an object with a list of data). To provide a more consistent initialization mechanism, there’s brace initialization

However, any curly braces initialization is either direct initialization or copy initialization, it's not a third form. I.e. this is a false dichotomy. Unfortunately this is not very clear in cppreference; the link I gave now goes to the relevant paragraph in the draft standard online.


Part 1.6

About missing initialization. The terminology discussion is a bit misleading, probably because the term "initialize" has multiple meanings in C++, particularly a narrow formal one related to constructors, and a more general informal one from C and programming in general. The text communicates that "initialize" has only the narrow formal meaning. That can make problems for students later on.

Not sure how this could be explained any better, though. It's complex, so perhaps pointing out that what's given is a simplified explanation that will be refined later.


Part 1.7

About naming things. I miss a short discussion of using non-English letters. Supported by the C++ standard (I believe roughly the same rules as in JavaScript), but decidedly not by all compilers, so best practice = use only the English alphabet.


Well, that's enough time used for me.

It appears to be a very good tutorial. Some small problems, but there's nothing like the void main and similar ungoodness that used to plague C++ tutorials in the past, and importantly, this tutorial addresses the practical problems that a student is likely to encounter. At least up till and including part 1.7 the information given will not lead anyone astray in the in-practice, but there are small points of terminology and classification of things.

1

u/[deleted] Jul 18 '23

[removed] — view removed comment

1

u/alfps Jul 18 '23

In my time the first and second editions of Stroustrup's "The C++ Programming Language", later also "The Annotated Reference Manual" by Stroustrup & Ellis, plus Turbo C++ and g++ compilers. There was no standard yet and the language was changing. I learned some incorrect things (e.g. with Turbo C++ a call to a virtual function from a constructor could execute the implementation in a derived class) that I had to unlearn later.

Even Stroustrup was learning, because the language he had created was changing in basic ways. E.g. the 2nd ed. of TCPPL had at least one instance of void main, probably invalid according to the ARM which served as language reference, and at any rate invalid when C++ got standardized. He didn't at first believe it when I later mentioned it in a C++ group.

And I guess both Stroustrup and I are still learning, for the language is still changing: there is no such thing as "learning C++" and be finished.