Imperfect C++, by Matthew Wilson, is an outstanding book that provides “practical solutions for real-life programming” in C++. It presents a wide variety of useful material that I haven’t found in any other book on C++. If you’re an experienced C++ programmer, you’ll have learned much of this material the hard way, but you’ll still find plenty of information that will hopefully come in handy down the road.
As I read, I like to jot down items of interest so that I can come back to them later. There was no shortage of interesting items in this book; here are some highlights.
- 1: Mechanisms for implementing constraints, contracts, and assertions.
- 2.3: Using
const to track down uninitialized member variables.
- 2.3.1: Calling private static methods from member initialization lists.
- 10.2.2: Using spin mutexes for synchronization with low contention.
- 10.3.3: Critical sections are as slow as mutexes on multi-processor Windows machines.
- 11.3.2: Using a spin mutex to guard local statics.
- 12.2-12.4: Visual C++ 7.1 optimization. (It supports Return Value Optimization, but not Named RVO. It supports almost every case of Empty Base Optimization, and every case of Empty Derived Optimization.)
- 15.1: Creating a good
null pseudo-keyword.
- 18.1: Using the
const keyword after the type. (I should really start doing that; old habits are hard to break, e.g. char const * instead of const char *.)
- 18.4: Implementing
true_typedef.
- 18.5.3: Using a
LocalClass typedef in implementation files to reduce differences between similar class implementations.
- 20. The power of shims.
- 24.6: The best way to implement a safe conversion-to-Boolean for a class.
One of my favorites quotes is in the introduction to chapter 6: “You get all that functionality just by typing a }.”
If it’s not clear already, I highly recommend this book to anyone using C++ to write “real-life” programs.