I know Fran from C++ On Sea where she hosted lightning talk nights for the last two years. She recently asked me if I would be interested in reading her book, Learn C++ by Example. It was on my radar for a while so I gladly said yes.
The foreword just made me more determined to read it. If Fran could convince Matt Godbolt to give some endorsing words, then she must have written an instrumental book!
And indeed, she did!
I don’t want to pigeonhole the book’s target audience, but if I had to, I would say that it’s for restarters. The book is about picking up new features introduced between C++11 and 23.
I find it important to have such books for two reasons. It’ll show how much the language evolved for people who are relatively new to C++. Showing that is important because it’s a sort of proof that the language is not dead but keeps getting better. The other reason why such books are useful is to give restarters a way to pick up the “new” features. Unlike in a book covering the full language for beginners, you’ll get the most important points without going through all the foundational details that such books need to explain to people completely new to a language.
Learn C++ by Example contains 9 chapters, starting with a more general one about the book and C++. The other 8 cover different areas of C++:
- Hello again, C++!
- Containers, iterators, and ranges
- Input of strings and numbers
- Time points, duration, and literals
- Creating and using objects and arrays
- Smart pointers and polymorphism
- Associative containers and files
- Unordered maps and coroutines
- Parameter packs and std::visit
Each of these chapters revolves around different small games that you can play from the command line. Imagine games like number guessing or a slot machine. I like this approach, it’s easier to follow through the chapters and learn about modern C++ features when you want to have something that works by the end.
Besides, the easier way to follow through is not the only advantage of this approach. This way, features are put in context. For example, Fran doesn’t only share what std::visit
is, but it’s introduced as a key element of the design of a slot machine game. This is much more effective than simply talking about the feature and how it might be used in real life.
Another thing I appreciate about the book is that it introduces some language-agnostic concepts to the reader, such as property-based testing or rejection sampling. From a wider perspective, it’s important to cover topics which are not only about the immediate language. After all, we are not simply C++ programmers, but software engineers. And after zooming in, talking about topics such as testing has such importance! Taking testing seriously can save billions of dollars one day, right?!
I recommend Learn C++ by Example not only to those who haven’t used C++ for a long while but also to those who have been using it but didn’t really keep up with the new standards and now feel it overwhelming to go through all the additions. This book will be a great start to immerse yourself in modern C++.
Connect deeper
If you liked this article, please
- hit on the like button,
- subscribe to my newsletter
- and let’s connect on Twitter!