Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

C++ x 2


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


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.