Effective C++

Posted on Aug 11, 2015
Berlin, Germany

Note: See my article on Meyers’ Effective Modern C++ here

Scott Meyers is an interesting guy. He has become one of the leading experts on C++, even though he himself says that he has never been a professionally software developer. That’s a fascinating admission and one that speaks to the slow standardization of best-practices in the technology industry. Meyers takes an academic’s approach to the analysis of software design, which affords the opportunity to maximize optimizations without sacrificing quality for things that most software developers are familiar with, like deadlines or other business reasons. In that sense, he is much like William Strunk, the original author of the Elements of Style that offers rules for writers and that many authors take as gospel, or a music theorist–that is, someone who fully understands the aspects that make renowned music great but may not be composers themselves.

My experience is with the second edition of this book, which was published in 1998. There is a third edition available, published in 2005, and if you have the choice between the two editions I’d recommend getting the newest, but they mostly cover the same topics. The newer version updates some things and has sections that the second doesn’t. My local library happened only to have the second edition available.

Because this book was published long ago, you may be wondering if it’s still relevant to modern software development. It’s a valid question, especially in light of Effective Modern C++, but the answer is unquestionably yes. Firstly, Meyers’ books build one on another and the ideas in Effective Modern C++ are often explained in relation to the rules in earlier books. Secondly, and more importantly, we all work with software that has been around for at least a decade, and most of us will be responsible for maintaining said software. In such cases we should attempt to maintain the style and programming choices that the original software was written with, for consistency’s sake. Alternatively, it is appropriate to write a module with newer C++11/14 constructs and keep the older code as it is, but the important thing is to avoid situations where new and delete are interspersed with shared_ptr and auto vars (implicit variable type inference).

This book is organized into 50 items, all of which are important to be familiar with and probably should be printed out and tacked onto the wall next to my desk. Alternatively, after you read this book you could compile one of your codebases with g++ with the flag -Weffc++, which will warn you if your code is not adhering to the guidelines in this book. Personally, I found Item 14 - Make destructors virtual in base classes and Item 11 - Declare a copy constructor and an assignment operator for classes with dynamically allocated memory particularly well-written and taught me new ideas. Item 44 - Say what you mean: understand what you’re saying doesn’t just apply to C++ but all programming languages, and is advice that any serious developer should respect.