14 thoughts to “C++ as a second language (Chrome University 2019)”

  1. I like Mr. Blume's videos. I have been programming in C since 1982 (before the author was born) and C++ since 1989. These are my thoughts.
    a) Header files for "*.c" files should be "*.h" and for "*.cpp" files should be "*.hpp". The exception being C++ source that has only functions in the header and the header has extern "C" surrounding the calls. Those C++ headers do end in ".h". This indicates that the code can be called and linked into C programs, even though the code is C++. Why do that? To call your C++ code from Java using JNI (used when writing Android apps).
    b) When using macros to prevent double inclusion of headers, the ending macro line at the bottom of the header should be formatted as "#endif // MUSICTYPE_H". Whenever you make a macro and the end is more than two lines away, add a trailing comment to the macro to indicate what it is terminating. That way you and others studying the code have an easier time figuring out what is going on.
    c) Destructors are super important! Let's say you are going to do something in your class that needs cleanup, for instance memory allocation. These are the steps: add a pointer to the class, set the pointer to NULL in the constructor, then delete the pointer in the destructor. Now you can go allocate. Never allocate before writing the cleanup code, that is how you forget and get leaks. Discipline is better than garbage collection. Garbage collection is better if you don't have discipline.
    d) RAII. I think what the author was saying was don't do anything that can fail in the constructor. Just do initializations.
    e) Everything is easy with raw pointers while references are problematic. References were created under the false belief that C++ programmers can't understand raw pointers. But classes are far more complex than raw pointers. References have introduced a host of problems while raw pointers offer unlimited power. Don't be afraid of –>, it looks better than a dot. C++ programmers think in both classes and pointers.
    f) I started programming in C before the standard library so I wrote all my functions, which still work on every computing platform to this day. When the standard library came out in the mid 1980s I studied them and said these calls are dangerous and have no protections, use them if you want an unstable program that will be prone to crashing.
    g) You can do everything with C++98. Newer versions allow you to do what you can already do in different ways, at the expense of portability.

  2. Great refresher of C++ as it's my main language that I'm purely self-taught in. What I like about the video is how you show the equivalent comparisons and the subtle differences between different languages.

Leave a Reply

Your email address will not be published. Required fields are marked *