Book Review – Effective modern c++
Meyers, Scott (2015). Effective Modern C++: 42 Specific Ways to Improve Your Use of C++ 11 and C++ 14. O’Reilly Media, Inc. Kindle edition.
I recently had an opportunity to review the book ‘Effective Modern C++’ by Scott Meyers. This book is a set of guidelines (referred to as ‘items’ in the book) for writing code the proper way on C++ 11 and C++ 14. It is not, and does not claim to be, a textbook on the fundamental concepts of modern C++. Instead, it provides practical insights into how to create industrial strength software by correctly using various important and new features of C++ 11 and C++ 14.
Some general highlights of the book:
The example codes given in the book are platform independent. And each guideline is explained in detail. The book follows very well explained conventions that make it a joy to read and easy to understand. At appropriate places, the book highlights the things to remember. The writing style is very engaging with lots of humor thrown in. The index is very well written.
Some specific highlights of the book:
Template type, auto type and decltype are important additions to the C++ language. The book starts with an overview of these concepts. The book also highlights some pitfalls associated with even minor modifications to the code.
Next, the book highlights the practical advantages of using the auto keyword. For example, the use of this keyword to handle uninitialized variables is highlighted. The book very effectively explains how the pitfall associated with the unsigned keyword can be avoided by using the auto keyword. The pitfall is the difference in the way the unsigned keyword is treated by 16 bit and 32 bit computers. Remarkably, the book then proceeds to highlight the rare scenarios where a use of the auto keyword can lead to trouble! I was happy to note that the author has taken the effort to highlight this point.
The chapter on some more features of modern C++ explains a number of hard-to-understand concepts in vivid detail. Some of these are as follows:
- The difference between using parentheses and curly braces.
- Scoped and un-scoped enum
- The importance of using the override
- Preference of the const_iterator keyword to the iterator
- Use of the noexcept
The topic of smart pointers gets a full chapter dedicated to it. The challenges with using raw pointers are well known in the C++ community. Smart pointers are an excellent alternative to them. All 4 types of smart pointers are well explained and their uses well demonstrated.
I really liked the chapter on move semantics and perfect forwarding. If ever there was a challenging topic to learn, these two topics would be at the top of the list! I can see that by devoting an entire chapter to this topic, the author has labored hard to write a book that has high practical value.
The next chapter is on lambda expressions. The author rightly points out that lambda expressions are a game changer in C++ programming. The book explains how these expressions can enhance the use of STL. It also explains how these expressions can be used to avoid dangling references.
Traditionally, C++ has provided limited support for multi-threaded programming. But, the current versions have completely eliminated that shortcoming. The book talks about the concurrency API in great detail. Task based programming is superior to thread based programming. This chapter shows how. It also explains the difference between deferred and asynchronous modes. Joinable and un-joinable threads have been awarded an excellent elucidation in this book. The book does an excellent job of explaining communication among threads using conditional variables.
The book ends with detailing circumstances under which the programmer will have to deviate from established programming patterns. This final chapter is like an icing on the cake and the author’s efforts in writing it are worth an applause.
Overall, this book is an excellent guide to the practical aspects of modern C++ programming. One of the minor shortcomings of the book was an absence of quizzes. But, since this book is not a textbook, this shortcoming can easily be overlooked especially given the high quality of the book.
Sourav Sahay is a technology expert with nearly 2 decades of experience in the software industry. He is a published author too. His book on C++ titled ‘Object Oriented Programming with C++’ came out in 2 volumes and has been published by the prestigious Oxford University Press. It has sold more than 50,000 copies worldwide. He is currently writing his second book, which is on Internet of Things. This book will also be published by the Oxford University Press and is slated to hit the stands next year.