C++: The Ultimate Guide!

Source: Authorized Reprinted from Programming Guide (ID: cs_dev)

Author: Programming Guide

Today, I saw a video online where the presenter mentioned that the current trend in learning paths is a complete set of arrangements. For example, in the Java learning path, most bloggers assume you will focus on Java backend development and attach a bunch of frameworks, even Docker and Kubernetes, which are not directly related to Java itself.

This gives a feeling of overwhelming pressure, as there is simply too much to learn:

C++: The Ultimate Guide!

C++ is similar; whenever the C++ learning path is mentioned, it usually includes books like UNP, CSAPP, APUE, Linux xxx, etc. However, to be honest, these are not closely related to C++ itself.

So today, I plan to provide everyone with a pure C++ learning resource/path that focuses solely on C++.

The number of books on C++ is vast, and I’m sure you have already seen the few classic C++ texts in various learning paths.

But that’s okay; you will still see their presence today, haha.

The biggest drawback of C++ is its complex syntax, making it difficult to learn and master.

Learning C might be sufficient with just K&R’s “The C Programming Language,” but in the world of C++, you cannot find a single book that suffices.

We live in an era that favors quick learning; most people find it hard to endure the long process of learning a language, which is why “Learn C++ in 21 Days” has sold quite well.

However, unfortunately, even 21 days, or even one or two years, is hardly enough to master C++.

To learn well, you must read a large number of books and even the standard library documentation.

Here, I roughly divide the C++ learning process into several levels:

1. Beginner

If you have no prior experience with C or other languages, I recommend looking at online C++ beginner tutorials, such as those on Ruanjian Tutorial or the Chinese C Language website.

During this process, you need to understand and master the most basic concepts common to all programming languages:

Variables, constants, types, loops, conditionals, arrays, strings, objects, input/output, etc.

Then, there are some C++ specific features, such as namespaces, references, templates, etc.

And how to use some classes from the STL, such as string, vector, find, etc.

Then, supplement this with a lot of practice.

Just the exercises from C++ tutorials are sufficient, like Narcissistic numbers, basic calculators, etc.

If you are not interested in these, you can try this website:

https://www.codewars.com/kata/search/cpp

It’s somewhat like LeetCode for algorithm problems, where there are a series of exercises available for each syntax point.

Moreover, it includes not only C++, but almost all programming languages can be practiced here:

C++: The Ultimate Guide!

You should be able to complete a beginner tutorial like Ruanjian Tutorial in about two to three weeks.

At this point, you should have a general impression of the knowledge points included in C++.

And you should be able to write programs of about a hundred lines, but it’s still challenging to write an excellent class.

Next, you need to engage in comprehensive and in-depth learning, which is the real entry point:

  • “Accelerated C++” (a classic textbook from Stanford University)

  • “C++ Primer” (comprehensive)

  • “The C++ Programming Language” (written by Bjarne Stroustrup, the father of C++)

These three books each have their pros and cons. The first one is concise, only two to three hundred pages, covering only the core and essential knowledge points.

The latter two are comprehensive, especially “The C++ Programming Language.”

The difference between these two is that one is written by a C++ master, and the other by the father of C++.

Some people online say that “C++ Primer” is currently the only book on the market that truly covers everything from beginner to advanced, suitable for novices;

“The C++ Programming Language” is a self-study guide for C++ experts, suitable for readers with a solid foundation in C++.

Therefore, the recommended order is:

“Accelerated C++” -> “C++ Primer” -> “The C++ Programming Language”

For such large textbooks, I recommend reading by theme. For example, “C++ Primer” is clearly divided into:

  • Basics of C++
  • C++ Standard Library
  • Tools for Class Designers
  • Advanced Topics

If you have some foundation, you can look at the table of contents and read the chapters that interest you; there is no need to start from the first page and read sequentially.

By the end of the beginner stage, you should master the following content:

  • Basic language

  • Classes and Object-Oriented Programming

  • Input/Output

  • String processing (libraries and regular expressions)

  • Container libraries

  • Generic algorithms

Although it seems like only a few keywords, each of them has a lot of content to learn.

During the learning process, make sure to type out every exercise yourself and think critically about them.

Use code to validate your ideas, especially in areas like pointers, references, constructors, destructors, etc.

When learning C++ and in daily development, remember these websites for quick reference on syntax usage and standard libraries:

  • cppreference
  • cplusplus
  • isocpp

2. Intermediate

After reading books like “C++ Primer,” the code you write may still lack efficiency and adherence to C++ standards.

There may even be memory-related bugs.

For example, returning a reference to a local variable from a function, often using pass-by-value instead of pass-by-reference-to-const.

Since C++ is a system-level programming language, you need to master some OS-related knowledge to use it better.

Especially in areas like memory compilation and linking, such as heap, stack, static linking, dynamic linking, etc.

There are also some unique concepts in C++, such as RAII resource management, value semantics and lifetimes, references, rvalue references, etc.

There doesn’t seem to be a single systematic book that can help you master these; you can only absorb and refine them from different books.

For this part, I am still on my way.

Here are some books that can help in these areas:

  • “Effective C++”

In summary, it helps you quickly learn the correct practices in C++.

Otherwise, you might need to write tens of thousands of lines of code to slowly figure it out.

  • “Self-Improvement for Programmers” & “CSAPP”

Helps you master some system-level programming knowledge, such as memory management, stack, linking, and other crucial concepts in C and C++.

  • “Linux Multi-threaded Server Programming”

This book is not strictly about C++, but it contains some chapters on C++ multi-threaded programming, locks, thread safety, and some good engineering practices in C++.

  • “Google C++ Style Guide”

Google’s C++ coding standards; writing code is a professional task, and writing code beautifully and professionally is also a skill.

Google’s coding standards are considered a benchmark in the C++ field.

Many coding standards at Tencent are also based on Google’s coding standards with some adaptive improvements.

Mastering good coding standards early in your programming journey is highly beneficial.

3. Advanced

The books mentioned above focus on how to use and make the best of C++.

In contrast, I believe that advancing means studying the specific implementations of language cases and deeply contemplating the design and evolution of the language itself.

This can be divided into three parts:

Part 1. STL Source Code

As Hou Jie said: “Beneath the source code, there are no secrets.”

To better use STL, one method is to read the STL source code or understand some implementations:

“STL Source Code Analysis”

This book explains the underlying implementations of the five major components of STL.

Including memory management, data structure implementations of various containers, algorithm implementations, etc.

It is recommended as a must-read, as it helps deepen the understanding of STL’s underlying mechanisms.

It also covers many frequently asked interview topics, such as memory pools, traits techniques, vector dynamic expansion, set, map, and their implementation principles.

Part 2. Object Model

“Deep Exploration of C++ Object Model”

This book revolves around one point: how objects in C++ are organized in memory.

Here are the chapter contents:

  • About Objects
  • Constructor Semantics
  • Data Semantics
  • Function Semantics
  • Constructor, Destructor, Copy Semantics
  • Execution Semantics

The first time I saw this book, I was deeply attracted; back in school, I read it for eight or nine hours a day and finished it in about a week.

After reading this book, I felt I had a deeper understanding of the underlying mechanisms of C++, such as multiple inheritance, diamond inheritance, and the underlying implementation of virtual functions.

Of course, some may argue that how objects are implemented at a low level belongs to the compiler’s implementation details rather than language standards, and one should not deduce standards from implementation details.

That said, mastering implementation details will still promote your understanding of C++.

Part 3. Language Design and Evolution

This part focuses on contemplating the design and evolutionary direction of many C++ syntax elements. You can refer to Bjarne Stroustrup’s FAQ and “Design and Evolution of C++.”

The significance of reading this book, to be pragmatic, may not greatly enhance your C++ programming skills, unlike “Effective C++” which has immediate effects.

However, it is very helpful for deepening your understanding of C++.

To better use C++ to build good and efficient systems, a deep understanding of the language itself is a prerequisite.

On the other hand, the book discusses many design philosophies and thoughts, which I believe will also be helpful when learning other programming languages.

4. About the Book List

In this article regarding books, my principle is to minimize the number of recommendations, as there are simply too many excellent books related to C++. I only want to highlight the most useful books for each stage.

Quality over quantity is key.

Reading books is similar; I recommend that you don’t necessarily need to finish every book. Deeply and thoroughly reading one technical book is more effective than skimming through many.

Of course, I will also provide a categorized C++ book list for everyone to reference later.

5. About Videos

For beginners, reading books may indeed be challenging to grasp the concepts, just like when I was a freshman and couldn’t understand the distinction between text stream files and binary stream files in the C language textbook.

Many things that are common knowledge to experienced individuals can be difficult concepts for beginners to comprehend.

Perhaps learning through lectures or videos might make it easier to get started. Here, I recommend the C++ videos by Professor Weng Kai from Zhejiang University.

Professor Weng’s videos on C, C++, and Java are very insightful and easy to understand; it can be said that the higher the level of the instructor, the easier it is to understand their lessons.

This is the link to the NetEase Cloud Classroom:

https://study.163.com/course/introduction/271005.htm

Additionally, I want to recommend some of Hou Jie’s series of courses:

C++: The Ultimate Guide!

When I first saw these titles: “Memory Management,” “C++11,” “STL Source Code Analysis”… (PS: Now these have been removed from Bilibili, but you can reply to Hou Jie in the Programming Guide WeChat account to get them.

I felt like I had struck gold; I watched all these videos during one winter vacation, greatly improving my understanding of C++ and memory management.

I am truly grateful to Bilibili, these instructors, and sharers, and I must thank the internet era!

They have made the dissemination of knowledge more convenient, lowering the learning threshold for newcomers, but of course, it has also indirectly intensified the competition, haha (escape).

Recently, I discovered a video by a foreign C++ game engine developer, which is a more casual and easy-to-understand tutorial series. I recommend it:

https://www.bilibili.com/video/BV1Ay4y1i7Z6

C++: The Ultimate Guide!

END

Here’s a piece of advice from Professor Weng Kai for students learning C++:

To learn C++ (computers), you must have a very strong mental state.

What does that mean?

Everything in C++ (computers) is created by humans; if others can think of it, I can too. There is no black magic in C++ (computers); everything is just something I don’t know yet.

One day, I will understand all the details!

C++: The Ultimate Guide!

C++: The Ultimate Guide!

1. Objects.equals has pitfalls

2. Redis master-slave, sentinel, Cluster all in one!

3. How to read Linux code in VSCode without lag? This method will make it fast!

4. Interviewer: Talk about the differences between ReentrantLock and synchronized?

5. A magical website that makes learning Git commands fun and interesting

C++: The Ultimate Guide!

C++: The Ultimate Guide!

Click to share

C++: The Ultimate Guide!

Click to like

C++: The Ultimate Guide!

Click to view

Leave a Comment