June 01, 2002
Books in BriefVictor Volkman
Victor reviews Exceptional C++: 47 Engineering Puzzles, Programming Problems, and Solutions and More Exceptional C++: 40 New Engineering Puzzles, Programming Problems, and Solutions.
Exceptional C++: 47 Engineering Puzzles, Programming Problems, and Solutions
More Exceptional C++: 40 New Engineering Puzzles, Programming Problems,
and Solutions The Exceptional C++ books by Herb Sutter follow squarely in the tradition of Scott Meyers Effective C++ books. Specifically, the books present the best practices of C++ in pursuit of better software engineering. In case theres any doubt of this, the glowing forward by Meyers in Exceptional C++ hammers it home. The primary stylistic difference is a matter of approach. Meyers begins with a guideline and then calls upon a large body of evidence to support it. Sutters approach poses a question, analyzes the possible answers in detail, and generalizes several guidelines as the outcome. In case youre skimming, the guidelines often repeat for emphasis. Either way, both authors have demonstrated that writing good code requires both knowledge and continuous vigilance of language fundamentals such as constructors, destructors, inheritance, templates, iterators, exceptions, and of course const. Exceptional C++ arose from such humble beginnings as weekly postings to the Usenet newsgroup comp.lang.c++.moderated. These missives collectively entitled Guru-of-the-Week (GotW) sparked weeks of heated discussions. Ultimately, they reached the eyes of other members of the ANSI C++ committee and finally have become the basis of this series of books. You can taste the GotW items at their official web site (http://www.gotw.ca/gotw/). As of this writing, 84 items are available online, the first 60 of which form the basis of Exceptional C++ and More Exceptional C++ . Exceptional C++ proves most lucid and useful in the chapters entitled Exception Safety Issues and Techniques and Class Design and Inheritance. Sutter clearly illuminates the dark corners of exception safety as it applies to the use of templates. In doing so, the author examines how to write exception-safe (works properly in the presence of exceptions) and exception-neutral (propagates all exceptions to the caller) generic containers. In these discussions, a simple example is posed, dissected to reveal its flaws, and a rigorous replacement written. One effective case study shows three short lines of code revealing 20 separate invisible execution paths depending on the combination of exceptions thrown. Class Design and Inheritance challenges you to examine your core beliefs on the whys of O-O design. Probably everyone can benefit from a review of the right way to do operator overloading to avoid extra temporary objects, unpredictable side effects, and counter-intuitive interfaces. Among the most important guidelines to me was this three-part one: When modeling is implemented in terms of, always prefer membership/aggregation, not inheritance. Use private inheritance only when inheritance is absolutely necessary such as when you need to override a virtual function. Never use public inheritance for code reuse. More Exceptional C++, the second volume in the series, continues many of the same themes: Generic Programming, Optimization, Exception Safety Issues, Inheritance and Polymorphism, Memory Management, and Thread-Safe Code. In Generic Programming, the author addresses predicates, traits, typename, partial specialization, and some container choice tradeoff rules. In this sequel, he also dredges up additional exception problems as they occur in constructors, destructors, inheritance, and parameter evaluation order. The rather brief chapter about Inheritance and Polymorphism provides the best analysis of Multiple Inheritance Ive ever read. The remaining chapters provide insightful examples of how to use auto_ptr correctly, how to create a function that returns a pointer to itself, how to simulate nested functions in C++, and rules for using namespace without hurting yourself. If youve followed me this far, you might be asking: should I immediately get both of these books, only the first, or maybe just the second? If you feel youve got an expert grasp of C++ fundamentals and maybe are even feeling a bit complacent about your skills, try Exceptional C++ . Since the second book refers back to some items in the first book, Id recommend thoroughly absorbing the first book before going on to More Exceptional C++ . And last of all, a warning: These books will bring out your inner language lawyer and may both start and perhaps settle arguments among your co-workers. Victor R. Volkman received a BS in Computer Science from Michigan Technological University. He has been a frequent contributor to Windows Developer Magazine 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.
|
|
||||||||||||||||||||||||||||
|
|
|
|