Channels ▼
RSS

Imperfect C++


Bjorn is author of the upcoming book Beyond the C++ Standard Library: An Introduction to Boost. He can be contacted at [email protected]


Imperfect C++: Practical Solutions for Real-Life Programming
Matthew Wilson
Addison-Wesley Professional, 2004
624 pp., $44.99
ISBN 0321228774

In Imperfect C++: Practical Solutions for Real-Life Programming, Matthew Wilson presents a guided tour of contemporary C++. Geared toward practicing programmers, the book has a particular focus on handling situations that arise in the real world. It is this property that sets Imperfect C++ apart from other such books: Wilson skillfully attacks problems that you'll eventually have to deal with when writing software.

Part I of the book covers the fundamentals: Why RAII is important, how contract programming helps build reliable software, and explains wrapper types, value types, and the like. Because this section sets the table for the rest of Imperfect C++, you'll probably read it fairly quickly. I admit to skimming through this part of the book, because it jumped between topics without really providing new details not found elsewhere.

Part II is filled with problems and solutions that arise in real-world programming. It includes chapters on how to deal with C++'s lack of a standard Application Binary Interface (ABI), dynamic libraries on different platforms, threading issues, and static functions/data (including an excellent display of popular singleton types).

Part III focuses on language issues, such as the lack of fixed-size integer types, the missing dimensionof operator, the inability to distinguish between pointers and arrays, the lack of a NULL keyword, the perils of bool, and other issues that have caused Wilson (and most other C++ programmers) grief. Also, Wilson presents his views on class layout and how to write proper if statements. While I don't agree with all of the items, I do take my hat off for him having the courage to argue for them. Feel free to flame him!

Part IV tackles conversions, and introduces the concepts of Casts, Shims, Veneers, and Bolt-ins. This is arguably the most innovative part of Imperfect C++—and it is great. Shims are simple in concept. They're another level of indirection for accessing (possibly unrelated) types, allowing for consistent coding and empowering generic code. Wilson defines several types of shims: Attribute Shims, Control Shims, Conversion Shims, and several composite shims formed using these basic ones. Veneers are used to add functionality (through inheritance of its parameterizing type) to other types, with the restrictions that it may not add virtual functions or nonstatic member variables. Bolt-ins are similar to veneers, but may substantially change the semantics of their parameterizing types.

Part V is devoted to C++ operators, with enlightening chapters on correctly handling Boolean conversions, how to use operator overloading for fast string concatenation, and why some operators shouldn't be overloaded at all.

Finally, Part VI picks up the pace through C++ extensions through class libraries. This is a great exposition of clever techniques and useful tools. Especially interesting are chapters on ranges (which are far more important than simply relieving you from the repetitious tedium of writing begin()/end() all over the place) and on implementing support for properties in C++. I also enjoyed the chapter on multidimensional arrays.

Imperfect C++ covers a lot of C++ ground, and the tempo is often challenging—so stay alert! You will also need to be fairly proficient in C++ to get the most out of the book, as basic concepts are only briefly mentioned. I do have a couple of issues with this book, and one is the title. While Wilson is often exposing flaws in the language, these imperfections are not the main attractions: This book is really about celebrating and exploring the virtues of C++. The other issue is that Wilson sometimes leaves you wanting more detail on mind-boggling techniques or compiler quirks, making me hope that he's already at work on "More" Imperfect C++. However, these are minor issues, and I highly recommend this book to serious C++ programmers. It is jam-packed with important lessons that are taught in a pedagogic manner. An especially sympathetic property of this work is the way Wilson always stays close and personal to the reader. The book is also funny—and considering that Wilson is from Yorkshire, I find this especially astounding. Finding computer literature with humor that is actually funny is a rare treat.

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.