C++ x 2

Jack Woehr reviews two C++ books this month.


July 01, 2005
URL:http://drdobbs.com/c-x-2/184406161

July, 2005: C++ x 2

Jack is a DDJ contributing editor. He can be contacted at http://www.softwoehr.com/ softwoehr/.


C++ Coding Standards: 101 Rules, Guidelines, and Best Practices
Herb Sutter and Andrei Alexandrescu
Addison-Wesley, 2005
240 pp., $34.99
ISBN 0321113586

C++ Template Metaprogramming: Concepts, Tools, and Techniques from Boost and Beyond
David Abrahams and Aleksey Gurtovoy
400 pp., $44.99
Addison-Wesley, 2005
ISBN 0321227255

Herb Sutter came to prominence with his "Guru of the Week" posting to the newsgroup comp.lang.c++.moderated. His Exceptional C++ (Addison-Wesley Longman, 2000; ISBN 0201615622), other books; and a regular column in the C/C++ Users Journal showed that Sutter has what it takes to teach C++ both entertainingly and rigorously.

Rigor is a concept relegated to the minority benches in the modern computer technological publishing stream. Do modern comp-sci and comp-eng students even hear the term? In C++ Coding Standards, Sutter and coauthor Andrei Alexandrescu touch ground on each of 101 suggestions (0-100 inclusive) for standardization of ways and means in your current C++ project. Welcome back, Herb.

The problem with trendy concepts such as UML, design patterns, and coding standards is that the clue-pursuing majority of working (more or less) programmers who track these trendy concepts tend to think that they mean something in and of themselves. Earth to programmer: They don't mean anything. They're just conveniences of locution, a way of talking about the abstract aspects of computer programming. It's the old Zen finger-pointing-at-the-moon thing: Do you want to gaze at the moon, or do you want to attend FingerCon 2005?

Sutter and Alexandrescu have reached satori. Standard concepts were made for programming, not programming for standard concepts. Everything they note is genuinely an issue, they're not just trying to scare you. All their didaction is informed by vast experience mingled with profound common sense. Standard concept number one, as it were: If you stay engaged, not becoming a codebot, and think about what you're doing as you're doing it, you're likely to have an idea or two about how you are doing it.

C++ Coding Standards is organized into 101 brief topics, each with a pithy title, summary, discussion, examples, exceptions to the rule, and references. Matters start at the mundane and climb towards the ineffable. The three first topics are "Don't sweat the small stuff," "Compile cleanly at high warning levels," and "Use an automated build system." Later, we're into the kozmik stuff like "Prefer providing abstract interfaces" and "Public inheritance is substitutability. Inherit, not to reuse, but to be reused." The authors' suggestions are, at the very worst, mildly suboptimal, while at best, they are sublime. Essentially, they have no methodology to peddle, no panacea to push. They just want to make life easier for you and your maintainers, and to that end, they raise as many questions in the alert reader's mind than they explicitly answer.

One gripe about this otherwise lovely book: The code examples were foolishly set in a rather loopy variable-width font. May we please have plain old typewriter-style, fixed-width in the next edition, please? The fully functional home page for C++ Coding Standards is at http://www .gotw.ca/publications/c++cs.htm.

C++ Template Metaprogramming, by David Abrahams and Aleksey Gurtovoy, is a really good intermediate C++ programmer's paper mentor as that intermediate programmer begins to plumb (appropriate metaphor) the depths of template programming. Templates, m4, PROLOG, the C preprocessor, and the make command, all share that similar quality of an enigma wrapped in a mystery folded into a puzzle. That quality that makes them baffling is their recursive descent through symbolic truth in pursuit of ground truth, be it the logical truth of an assertion, the expansion of a macro, or the resolution and instantiation of a template.

Abrahams and Gurtovy have written something close to a classic in C++ Template Metaprogramming. This book isn't about learning C++ template programming. This book is about conquering the world, nyah-hah-hah, using templates to perform compile-time computation! I could wax ironic about IMMEDIATE words in Forth accomplishing the same thing circa 1972, but instead offer a cheery "Welcome belatedly aboard!" to our brother and sister compiler jockeys.

C++ Template Metaprogramming is marvelous fun to read. It's nothing you really need to know, nothing that you are obligated to learn, neither in terms of the specification of the C++ language nor with respect to the posted requirements of your job. Instead, it's a refreshing walk through the sylvan glades that sprang up magically of their own accord, above and beyond the intentions of the creators, when a Good and Simple Idea (here, the C++ template language) was gratuitously embedded in a programming regimen. In a professional practice increasingly constrained by formality, herded by integrated development environments, straitjacketed by approbated design patterns, isn't it wonderful that unheralded beauty can push through the cracks in the asphalt?

C++ Template Metaprogramming is wholesome, brilliant, expertly written, well laid out, and incidentally offers a great deal of immensely useful practical tips about using and debugging C++ templates. The section on wading through compile-time error messages, which we all know tell you everything and nothing about what went wrong during template expansion, is alone worth the price of admission to those who have never touched base at that particular Rosetta Stone.

The book comes with a CD containing a wealth of material above and beyond the examples in the book, including three code libraries. The book's home page, with errata and workarounds for nonconforming compilers, is found at http://www.boost- consulting.com/metaprogrammingbook .html. Addison-Wesley's page for the book, including sample chapter and index, is at http://www.awprofessional.com/titles/ 0321227255.

DDJ

Terms of Service | Privacy Statement | Copyright © 2024 UBM Tech, All rights reserved.