REVIEW - Modern C++ Design - Generic Programming and Design Patterns Applied


Title:

Modern C++ Design

Generic Programming and Design Patterns Applied

Author:

Andrei Alexandrescu

ISBN:

Publisher:

Addison-Wesley Professional (2001)

Pages:

323pp

Reviewer:

Francis Glassborow

Reviewed:

February 2001

Rating:

★★★★★


By the time you have finished reading and thinking about this material you will wonder why you ever doubted the power of C++ templates.

As some readers know, I try to grab a high proportion of the truly awful books so as not to burden others with the task of trying to be honest though kind. As you can guess, I also get first pick of the really good ones, or at least the ones I think will be good. I particularly look out for books that either set a new standard of excellence in an existing category or that open up an entirely new area. Books like Accelerated C++ fit the first category and those such as Generative Programming fit the second. This book is very definitely in the second category.

Let me first get my biggest criticism out of the way. The title is deeply misleading, probably a candidate for most misleading title of the year. The subtitle, Generic Programming and Design Patterns Applied is much better. The book should have been given a title such as Modern C++ Template Techniques .

Next let me comment on the quality of Andrei's English. It would be hard to guess that Andrei is not a native English speaker (he is an expatriate Rumanian). The quality of his technical writing sets standards that many others might aspire to. Every now and again his English shows that he is not a native speaker. Sometimes his (lack of) use of the definite and indefinite articles has crept past the copy editor actually many publishers cut costs on this element of preparing a book for publication.

Regular followers of comp.lang.c++.moderated (and if books like this one interest you, you should be reading that newsgroup) will be familiar with Andrei's insightful contributions. This book is the distillation of many of the ideas he has placed before us over the last couple of years. The first part of the book consists of four chapters that introduce various template techniques. In the first chapter he shows how templates can be used to support policy-based design. This is a design mechanism that should certainly be in the repertoire of any competent programmer.

In the next chapter he introduces half a dozen techniques such as using templates for compile time assertions, type to type mapping, type traits etc.

Chapter 3 introduces one of the really remarkable template mechanisms that Andrei has developed. The core of this idea is:

template class struct Typelist {  typedef T Head;  typedef U Tail; };
The rest of the chapter expands on how to make best use of this idea. One warning I should give you is that you will need a compiler that supports template template parameters like, for example, that in the following declaration:

Template class Unit> Class GenScatterHierarchy;
This is bleeding edge technology, but if you want to understand why such things are in C++ books like this one may persuade you of their utility.

Chapter 4 develops a special allocator for small objects, which will remove much of the pain when you are developing an application that relies heavily on the dynamically allocated small objects.

The second part of the book concerns components. The chapter titles are:

Generalized Functors,
Implementing Singletons,
Smart Pointers,
Object Factories,
Abstract Factory,
Visitor
Multimethods
.

By the time you have finished reading and thinking about this material you will wonder why you ever doubted the power of C++ templates. As you read the current hype surrounding C# you will wonder how any C++ programmer would wish to return to the bad old days and forgo the tools that template technology offer.

If you want to sample a single chapter, have a look at the one on smart pointers which will demonstrate the power of the policy based templates from chapter 1.

If you think I am wildly in favour of this
book, you would be dead right. This is not a book for novices but if you are serious about
your programming and count C++ in your programming tools then you owe it to yourself to get this book and study it. It isn't just the explicit contents that matter but the whole approach to using C++. Reading this book will do one of two things, make you a much more skilful C++ programmer or persuade you that you still have far to go to become a master of C++. Perhaps both.

The final icing on the cake is that the ideas incorporated in this book are encapsulated in the author's Loki library that is available free on the Internet.

Those that come to The ACCU Spring Conference 2001 http://www.accu.org/events/public/accu0103.htmwill get a chance to meet the author in person. Personally I think that is just one of half a dozen reasons that you should come to that event.


Book cover image courtesy of Open Library.





Your Privacy

By clicking "Accept Non-Essential Cookies" you agree ACCU can store non-essential cookies on your device and disclose information in accordance with our Privacy Policy and Cookie Policy.

Current Setting: Non-Essential Cookies REJECTED


By clicking "Include Third Party Content" you agree ACCU can forward your IP address to third-party sites (such as YouTube) to enhance the information presented on this site, and that third-party sites may store cookies on your device.

Current Setting: Third Party Content EXCLUDED



Settings can be changed at any time from the Cookie Policy page.