Adam Petersen - Software Development Pages, Book Reviews Section
Start News Articles Book Reviews

Book Review

Advanced C++ Programming Styles and Idioms
by James O. Coplien

ISBN: 0201548550
Publisher: Addison-Wesley Professional
Pages: 544


Written in an age as C++ was young with its standardization still years away, this book describes a language no longer understood by today’s compilers. However, as style doesn't go out of fashion and true idioms are long-lived, has the book stood the test of time?

It's rare but pleasant to encounter a book labeled as "advanced" that actually make that claim hold true. The included idioms bring a tremendous flexibility to C++. The introduction of exemplars illustrates how increased run-time flexibility is achieved in C++. Greatly simplified, exemplars are a way to emulate dynamic type changes (i.e. changed behavior of an object). Exemplars lay the foundation for more advanced idioms to come, like emulating symbolic languages including techniques to dynamically load and replace virtual functions. Idioms like the latter sure aren't trivial; neither from a conceptual perspective nor from the highly platform dependent implementation aspect.

Almost fifteen years have passed since this book hit the desks. At that time patterns weren't well-known in software development. Judging from Coplien’s later work in the patterns community, had the book been written some years later, I guess he would have used a pattern form to capture the idioms. The book would definitely benefit from such a more structured approach. For example, Coplien discusses important trade-offs and difficulties with the idioms. Unfortunately these consequences of applying a certain idiom are buried in the text and not immediately accessible. A reader has to scan the complete section and extract them himself. Alone making the trade-offs more visible would be a huge improvement. I found this particularly important as many of the idioms imply a style that isn't natural C++.

As I mentioned initially, the code is written in what is now ancient C++. The difference is larger than just a few keywords and namespaces. For example, the code is not exception safe and a reader should be well-versed in C++ in order to "translate" the examples into modern C++. For such a reader, however, the book still has much to offer.

Coplien was well before his time. Several of the idioms achieved later fame outside the C++ community, although with different names and form, in the seminal book Design Patterns. Just to give some examples, Coplien illustrates how operator-> can be overloaded for implicit forwarding to a delegate object. This technique is useful when implementing variations of the design pattern Proxy and, more specifically, its idiomatic version of reference counted pointers. The idiom used to decouple the classes in an exemplar-hierarchy is really just a variation of the design pattern Chain of Responsibility, although it's presented here as the Autonomous Generic Exemplar Idiom. And of course, exemplars themselves rely on the Prototype pattern.

The book actually reminds me of Alexandrescu's Modern C++ Design in that it stands as a great sample of out-of-the-box thinking and remarkable creativity. Together with Design Patterns, Coplien's book is one of those classics that I would love to see an updated second edition of.

Reviewed December 2005


©2005 Adam Petersen adam@adamtornhill.com