Tuesday, 2 January 2007

Book Review: Modern C++ Design

Weighing in at just over 300 pages, this book might not initially seem like it has much to offer. However this couldn't be more wrong. Andrei has packed a wealth of knowledge into every page of this book making it an invaluable tool.

When I first read this book I was in my first year at University and to be honest it meant nothing to me. If you had asked me then if I would have recommended it to anyone I would have said no. It's only since reading it again recently after writing real world C++ code, that it really starts to make sense.

This is really not a book for someone just learning C++. It tackles some of the more advance topics of C++, mostly revolving around templates and there use as a design tool. It does not teach templates themselves and assumes the reader has a good grasp of C++, so if you've been coding C++ for a couple of years at a reasonable level then this will be a good book for you.

The main focus of the book is taking common design patterns and creating generic implementations using templates that allow you to easily customise behaviour using different policies, which are provided in the form of small easily maintainable classes that implement very specific features in a generic fashion.

The start of the book introduces the concept of policy based class design along with techniques to allow you to recognise and extract policies from existing classes.

The book then moves on to explaining techniques to control the allocation of memory and typelists. Typelists are both elegant and breath taking, they really show the power of template meta programming to create code for you at compile time.

The above ideas and techniques are then used throughout the second section of the book, which takes commonly used design patterns and shows ways of extending there functionality easily using templates and policies, as well as introducing a high level of flexibility.

When dealing with the design patterns, Andrei first begins with pointing out the problems with the current pattern and then proceeds to set out a plan to improve it. This way instead of just being given a set of step by step operations to implement a certain design pattern, he points out the pitfalls of using the patterns and attempts to offer a solution to the problem, educating the reader rather than just holding their hand.

A lot of the code presented in this book is aimed at library writers. It attempts to create a flexible library of code that could be used along side the standard library to make common design tasks easier to implement. This however should not put you off if this is not your area of coding as there is still a lot to be learnt from this book even if you don't use it every day.

I would highly recommend this book to anyone who wants to be a serious C++ developer.

0 comments: