Title: Embracing Modern C++ Safely
Authors: John Laos, Vittorio Romeo, Rostislav Khlebnikov, and Alisdair Meredith
Publisher: Pearson Education, Inc.
Year: 2022
C++ is a complex language. Fortunately, we have several good books (and other online material) for programmers at various levels. A few weeks ago, I had reviewed and recommended “Beautiful C++”, book suitable for intermediate to advanced programmers. Today, I am thrilled to write about another excellent book that is targeted at advanced programmers.
What makes this book special is that its focus is on “safety” in the context of C++ language features. According to the authors, “safe” features are those that “add considerable value, are easy to use, and are decidedly hard to misuse unintentionally”. They additionally introduce two variants of safety: “conditionally safe” and “unsafe”. Conditionally safe features have some inherent limitations and hence in order to use them correctly, programmers require adequate training and extra care. Unsafe features are those that can be counterproductive in a large-scale project when used routinely. Exploring C++ from the perspective of “safety” reveals many interesting practical aspects of the language and writing an entire book on this theme is a challenging task indeed.
The book contains three main chapters, corresponding respectively to the categories of safety introduced above:
Chapter 1: Safe Features
Chapter 2: Conditionally Safe Features
Chapter 3: Unsafe Features
Each chapter includes features from C++ 11 and C++ 14. While explaining each feature, the authors follow a structured format, covering its syntax and semantics with several non-trivial examples, potential pitfalls, annoyances, and pointers to further reading.
I do not want to spoil the excitement by revealing the list of features discussed in the book. So, let me mention just one feature from each of the three categories:
1) Safe feature => “override” member function qualifier
2) Conditionally safe feature => “noexcept” operator
3) Unsafe feature => “final” member function qualifier
For anyone who has been programming in C++ for a few years, these might come as a bit of a surprise, but believe me, when you go through the explanation given in the book, you will definitely appreciate why the authors have classified a feature the way they have done!
The authors have to be congratulated for presenting the material very objectively, based on “facts and not opinions”. This is very important because the book is not about “guidelines”. Also, the authors do not just skim over each feature, but explain it thoroughly. The presentation assumes that the reader has a good grasp of C++, and so this book will not appeal to beginners. The authors are highly experienced C++ programmers and naturally, reading the book (almost an encyclopaedia with over 1300 pages) is very rewarding experience (although occasionally intimidating!)
My only disappointment is that such a great book stops with C++ 14. Of course, the authors adequately justify why this is so and I am with them. Developers are already using C++ 17 and C++ 20 features and a book of this nature will benefit them immensely. I fondly hope that the authors come out with an updated edition in a year or two, which covers the more recent standards.
Have a nice week!
Recent Comments