Book Review: Imperfect C++

Imperfect C++
by Matthew Wilson
Addison-Wesley, 2004
588 pages + CD, $44.99
Code in C++
ISBN 0-321-22877-4

Matthew Wilson is a columnist for C/C++ Users Journal and fearsomely knowledgeable about C++. This book is an excellent work, with the subtitle "Practical Solutions for Real-Life Programming." Don't get confused by the title, though; if you're looking for affirmations that your own slipshop programming techniques are OK, you've come to the wrong place. Instead, this is a book that pinpoints some of the weaknesses and annoyances of C++, and then shows you how to work around them.

Beware, it's not for the faint of heart or the new of language. Before you tackle this one, you should at least have dipped into Bjarne Stroustrup's The Design and Evolution of C++ and be comfortable reading things on the level of Herb Sutter's Exceptional C++ or Scott Meyers' series of Effective C++ books. If you're at that level, where advanced C++ concepts don't scare or confuse you, you're ready for this book.

Here are some examples of the sort of imperfection that Wilson discusses:

  • Function-local static instances of classes with nontrivial constructors are not thread-safe.
  • C and C++ arrays decay into pointers when passed to functions.
  • Over loading the && and || operators for class types represents an invisible breaking of short-circuited evaluation.
  • C++ does not provide properties.

There are lots more, of course. Each identified imperfection leads into a detailed discussion of what's going on (with tests across multiple compilers in many cases) and then ideas on how to fix it. Sometimes this involves just not using dangerous constructs, sometimes Wilson builds new templates to do what he wants the language to do, sometimes he comes up with alternative ways to tap the power of the language.

The tone of the whole is excellent. This is not a dry work of pedagogy, but something much closer to the transciption of a good series of lunch discussions with experienced developers. Wilson throws in a little humor, but not so much as to be annoying, and he explains things in a straightforward way. You also get a CD with the Arturius "compiler multiplexer" (a tool to let you see how different compilers treat the same code), some compilers, sample code, articles, and other goodies.

About the Author

Mike Gunderloy has been developing software for a quarter-century now, and writing about it for nearly as long. He walked away from a .NET development career in 2006 and has been a happy Rails user ever since. Mike blogs at A Fresh Cup.

Featured

Upcoming Events

AppTrends

Sign up for our newsletter.

I agree to this site's Privacy Policy.