Bjorn is author of the upcoming book Beyond the C++ Standard Library: An Introduction to Boost. He can be contacted at [email protected]
Imperfect C++: Practical Solutions for Real-Life Programming
Addison-Wesley Professional, 2004
624 pp., $44.99
In Imperfect C++: Practical Solutions for Real-Life Programming, Matthew Wilson presents a guided tour of contemporary C++. Geared toward practicing programmers, the book has a particular focus on handling situations that arise in the real world. It is this property that sets Imperfect C++ apart from other such books: Wilson skillfully attacks problems that you'll eventually have to deal with when writing software.
Part I of the book covers the fundamentals: Why RAII is important, how contract programming helps build reliable software, and explains wrapper types, value types, and the like. Because this section sets the table for the rest of Imperfect C++, you'll probably read it fairly quickly. I admit to skimming through this part of the book, because it jumped between topics without really providing new details not found elsewhere.
Part II is filled with problems and solutions that arise in real-world programming. It includes chapters on how to deal with C++'s lack of a standard Application Binary Interface (ABI), dynamic libraries on different platforms, threading issues, and static functions/data (including an excellent display of popular singleton types).
Part III focuses on language issues, such as the lack of fixed-size integer types, the missing dimensionof operator, the inability to distinguish between pointers and arrays, the lack of a NULL keyword, the perils of bool, and other issues that have caused Wilson (and most other C++ programmers) grief. Also, Wilson presents his views on class layout and how to write proper if statements. While I don't agree with all of the items, I do take my hat off for him having the courage to argue for them. Feel free to flame him!
Part IV tackles conversions, and introduces the concepts of Casts, Shims, Veneers, and Bolt-ins. This is arguably the most innovative part of Imperfect C++and it is great. Shims are simple in concept. They're another level of indirection for accessing (possibly unrelated) types, allowing for consistent coding and empowering generic code. Wilson defines several types of shims: Attribute Shims, Control Shims, Conversion Shims, and several composite shims formed using these basic ones. Veneers are used to add functionality (through inheritance of its parameterizing type) to other types, with the restrictions that it may not add virtual functions or nonstatic member variables. Bolt-ins are similar to veneers, but may substantially change the semantics of their parameterizing types.
Part V is devoted to C++ operators, with enlightening chapters on correctly handling Boolean conversions, how to use operator overloading for fast string concatenation, and why some operators shouldn't be overloaded at all.
Finally, Part VI picks up the pace through C++ extensions through class libraries. This is a great exposition of clever techniques and useful tools. Especially interesting are chapters on ranges (which are far more important than simply relieving you from the repetitious tedium of writing begin()/end() all over the place) and on implementing support for properties in C++. I also enjoyed the chapter on multidimensional arrays.
Imperfect C++ covers a lot of C++ ground, and the tempo is often challengingso stay alert! You will also need to be fairly proficient in C++ to get the most out of the book, as basic concepts are only briefly mentioned. I do have a couple of issues with this book, and one is the title. While Wilson is often exposing flaws in the language, these imperfections are not the main attractions: This book is really about celebrating and exploring the virtues of C++. The other issue is that Wilson sometimes leaves you wanting more detail on mind-boggling techniques or compiler quirks, making me hope that he's already at work on "More" Imperfect C++. However, these are minor issues, and I highly recommend this book to serious C++ programmers. It is jam-packed with important lessons that are taught in a pedagogic manner. An especially sympathetic property of this work is the way Wilson always stays close and personal to the reader. The book is also funnyand considering that Wilson is from Yorkshire, I find this especially astounding. Finding computer literature with humor that is actually funny is a rare treat.