FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
Dobbs M-Dev
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
September 01, 2001
Books in Brief

Victor Volkman
Victor Volkman
Modern C++ Design: Generic Programming and Design Patterns Applied, by Andrei Alexandrescu, and Applying UML and Patterns, by Craig Larman.
September 2001/Books in Brief


Modern C++ Design: Generic Programming and Design Patterns Applied
Andrei Alexandrescu
332 Pages
Addison Wesley, 2001
$39.95
ISBN:0-201-70431-5

Modern C++ Design challenges you to take a bold leap of indirection to a new plateau of design. Specifically, Alexandrescu attempts to fulfill the promise of design pattern techniques using C++ templates as the generator. It is an article of faith that patterns cannot be represented in raw code. However, template generated pattern implementations are efficient, flexible, and provide a high degree of compile-time enforcement of correctness. In particular, the author details template-generated implementations of Visitor, Singleton, Command, and Factory patterns. But there’s a lot more to this book than simply how to use patterns. Though it’s never mentioned formally in the text, the underlying technique employed is truly metaprogramming.

The author correctly states the ideal intended audience as experienced C++ programmers. For students considering the text, I would recommend that you have four semesters of C++ under your belt. Most importantly, I recommend a data structures course where you were required to implement abstract polymorphic data types using templates. Absent of this background, most of the issues of templatized reusability and compile-time class identification will seem like esoteric proofs. Alternately, you could argue that the Loki library provided is worth the investment alone for its eminently practical smart pointer classes, typelists, pattern implementers, and other goodies. Naturally, the risk you assume in taking on Loki is proportionally reduced by your level of understanding of its implementation.

A quick look at the bibliography and you could conclude that this might have been subtitled “the best of Alexandrescu” as it draws on previously published material from C++ Report and C/C++ Users Journal. Modern C++ Design takes on so many different problem solving techniques even listing them all is beyond the scope of this review. Policy classes neatly tie up the problem of permuting class characteristics by way of template-template parameters. Detecting convertibility and inheritance at compile time yields to the power of partial specialization. Manipulating typelists (collections of types) works to the detail where entire class hierarchies can be generated or queried at compile time via template recursion. Generalized functors become simpler with templates and pointer-to-member functions. Final chapters delve into double-dispatch (multi-methods), abstract factories, and brief comments on multithreading safety.

Since Loki continually pushes the envelope of compiler conformance and compliance, it is of necessity very much a work-in-progress. At the time of my writing, its last update was June 20, 2001. Weighing in a mere 6,500 lines of code, its size belies its considerable capabilities. Though it promises compatibility with Metrowerks CodeWarrior Pro 6 under Windows, gcc 2.95.3, and Comeau C++ 4.2.38, there are small workarounds required for using Loki with CodeWarrior. My own ad-hoc testing with Visual C++ 6.0 SP3 abandoned after reporting 100 syntax errors. In a very real sense, “Modern C++” might have been titled “Future C++”: Alexandrescu has thrown down the gauntlet for compiler writers. Where other academics disdain to even mention the lowly atavistic macro processor, he turns it to good advantage by improving readability of client code.

As an advanced C++ programmer, if you have the time, energy, or inclination to read only one C++ book this year, my recommendation is pick up Alexandrescu’s Modern C++ Design.

Applying UML and Patterns, 1st Edition
Craig Larman
500 pages
Prentice Hall, 1998
$49.00
ISBN:0-13-748880-7

I picked up Larman’s book as a relative UML novice. My only prior experience with UML had been a couple of odd hours at a past Software Development conference and a recent week-long internal training course (based on ObjectMentor materials). Having yet to apply UML “on-the-job,” I consider my novice prespective relatively accurate. An even larger 2nd Edition of Applying UML and Patterns is in the works for 2001 but not yet released as of this writing. If you can’t get enough of Larman, there is a three hour video lecture of this title available for $149.

Weighing in at more than twice the size of the other highly popular reference UML Distilled, 2nd Edition, you might quickly conclude that Larman’s work was more comprehensive. In reality, most of the additional size is devoted to the many diagrams provided. A page of text without an illustration is so rare you will be turning pages relatively quickly. Since this is indeed a text about diagramming, one cannot find fault for using too many diagrams. Subdivided into 40 chapters and eight parts, the text also devotes substantial space to introducing and summarizing each of them.

Most UML approaches I’ve seen thus far tacitly assume that every type of diagram is of equal value or importance. Larman finally weighs in on this issue in chapter 17, declaring that the interaction diagrams really are the most important. State diagrams appear in a quick 10 page chapter. Since these have existed for decades, only the semantics of UML symbols need be addressed.

A text on diagramming should strive to be language-neutral. Larman tries to spin most implementation issues mostly towards Java with concessions for C++. Pseudocode appears most often except for a 200-line implementation of the POST (point-of-sale terminal) problem in Java.

The only disappointment I had with the text was the choice of POST as the primary illustrative case study. The author offers an apology since a similar case study was offered in Peter Coad’s seminal work Object Models: Strategies, Patterns, and Applications (1995). Nevertheless, Larman supplies an independently developed solution albeit to the same problem. I admit to acquiring a profound apathy towards the POST case study after the first 300 pages of endlessly revisiting the same transaction.

The scope of this sort of text doesn’t include the real-world issues of how the developer can use UML to manage expectations of supervisors and customers. Must they buy-in on the entire model? How do you keep people motivated to maintain all these diagrams accurately until the end of project occurs?

I will also admit to being a relative novice in the arena of design patterns. As such, I was curious as to how the patterns would be integrated with UML. I found the Expert and Creator patterns to be interesting in theory though insufficient to characterize real-world classes. When the sophisticated patterns are introduced in chapter 34, each is quickly sketched in two to three pages or so. GRASP itself seems to be mainly a grab-bag of patterns, in a sort of best practices vein. Applying UML and Patterns will give you a taste of patterns, but defers in-depth discussion and coding to footnotes.

Applying UML and Patterns is a measured and well-paced introduction to UML. Only a rudimentary knowledge of OO design is required. For example, any student with two or three semesters of Java or C++ will be amply prepared. I would recommend this book without hesitation as a primary text in a sophmore level computer science course. For those learning in a self-study mode, a high level of motivation will help you through.

Victor R. Volkman received a BS in Computer Science from Michigan Technological University. He has been a frequent contributer to Windows Developer’s Journal since 1990. He is the author of C/C++ Treasure Chest, which includes 300 products on CD-ROM. He can be reached by email at sysop@HAL9K.com or through http://www.HAL9K.com.

TOP 5 ARTICLES
No Top Articles.



MICROSITES
FEATURED TOPIC

ADDITIONAL TOPICS

INFO-LINK