Generic Programming: Modern C++ Design
I heard of this book from some of my programming friends, and decided to get it myself. So I purchased a copy of this book two days ago. Only the low-price edition was available but I decided to buy it anyway even though the paper quality could not have been made any lower.
There are many articles that already talks about this book in detail, so I'll shift my attention to how much of this maybe practically applied.
Right from the word go, this book kicks-off with some advanced concepts like Policies and using templates to alter not just behaviour but structure as well. It doesn't have the gradual basic to more advanced approach that most books have. But this is also why I like it. I don't want a fat book that wastes a few chapters on template containers and iterators. Those are the things that are almost synonymous with template usage in C++. But this book starts head on with a radical approach.
The first chapter itself deals with using template template parameters and user selectable creation policies. Right away it makes you feel templates are far more powerful than ever imagined. The elegance of using these features, albeit pretty complex both syntactically as well as semantically, could enable us to design programs with extreme flexibility.
As I read more on this book, the question that pops to my mind is, "How the hell did he think of doing it this way.". The next, more important question that follows, "Would I be able to apply these concepts in my own problematic design scenarios? Or would I go back to abstract & virtual functions for my generic needs?".
For now the answer to this question looks 50-50. Although I'm able to grasp the concepts mentioned therein, the practical usability of these concepts seems improbable.
Half the time I relate to the concept with my own program scenario, like a GUI builder that was planned for MakeMe. Back then I was sure I wanted to do it in an extremely generic fashion, to the extent of a completely extendible, yet user friendly widget interface that third party developers would find a breeze to add their own widgets to MakeMe. But I never finalized on any design pattern. Now I think I've got a better idea of how to go about it.
The rest of the time, the concept appears to be way to abstract. But as time goes I think I will be able to relate to these better.
My brother, apparently also written about this book here, was almost certain he did not want much to do with it. He ended up by saying he prefers good old C. But I'm much more in favour of C++. Maybe because of my years of programming in BeOS which forces you to use multi-threading and objects has squeezed my thinking of a problem straight away in terms of Classes and Objects. My continuous reading of the BeOS API and every open source BeOS program has helped a lot in shaping my thought pattern of the problem domain. I remember spending many months rewriting large pieces of code for trivial design problems, but today I can say with confidence my problem-solving approach is primarily object oriented (C++) than procedural (C).
One thing I agree with my brother is, in an organization where many people touch and tangle code, such advanced and carefully written code could easily be broken. The person writing such radical and elegant designs may not stick around with the company to enforce it, and thus the code could be 'ruined' quite quickly!
All said and done, some of the things in this book are pure genius. For instance, the compile-time assertion using partial template specialization and typelists that Andrei builds simply brings a smile.
I'll conclude by saying this book is probably the most interesting programming books I've ever read. It is also an extremely no-nonsense book that doesn't waste pages explaining unwanted theories. and explains all the concepts with easy to understand code. It is targetted for a specific audience, and stays focused!
0 comments:
Post a Comment