Book Reviews


C++ Programming Style

Reviewed by Steve Halladay


Steve Halladay manages software development for DATASONIX in Boulder, CO. He recieved his MS in Computer Science in 1982 and has over 10 years experience developing products like CSIM and Multi-C in C and C++. You can reach Steve at DATASONIX (303) 545-1807.

C++ combines the power of C with the flexibility of OOP to offer programmers a wealth of expression. Strong programmers use the semantic richness of C++ to build great programs. However, the power and flexibility of C++ makes it easier than ever for programmers to become hopelessly entangled. Even within the domain of published C++ examples, programmers demonstrate many poor practices. In his book C++ Programming Style, Tom Cargill insightfully shows programmers how to identify and replace poor C++ practices with stronger and more robust techniques.

Organization and Content

The focus of C++ Programming Style is to derive rules for better C++ programming. Cargill demonstrates the rules he derives by improving code examples he has collected from various sources. Here are some typical examples of rules from the book:

The use of rules is reminiscent of Kernighan and Plauger's classic, The Elements of Programming Style. In fact, Cargill uses the format of Kernighan and Plauger's text as a pattern. Like Kernighan and Plauger's book, C++ Programming Style expects the reader to be fluent, but Cargill explains the details of any obscure or less obvious C++ constructs.

C++ Programming Style has 233 pages and 11 chapters. The first chapter is a brief introduction that sets the stage for the remainder of the book. Each of the remaining chapters focuses on one specific concept. The chapter titles describe the focal point of the chapter. They include:

Chapter 0. Introduction
Chapter 1. Abstraction
Chapter 2. Consistency
Chapter 3. Unnecessary Inheritance
Chapter 4. Virtual functions
Chapter 5. Operator Overloading
Chapter 6. Wrappers
Chapter 7. Efficiency
Chapter 8. A Case Study
Chapter 9. Multiple Inheritance
Chapter 10. Summary of Rules

Each chapter takes an example class and shows how to apply the chapter's concept to improve the code. Thumbing through the book reveals that the average page is roughly 50% code example and 50% textual explanation of the example and concepts. The code examples are real, but not too long or overly complex. Cargill makes many improvements to each code example. He walks the reader carefully through each code change and explains why the change is an improvement. Along with discussing how to improve the code, Cargill shows the complete refined code to allow the user to compare easily the before and after views of the code.

Cargill starts each chapter by challenging the reader to improve the chapter's code examples. He proceeds by pointing out defects and weaknesses in the code and showing how to fix them. As he fixes the various problems, he points out the rules of thumb that apply to effect the change. Each chapter ends with a brief summary, a section of rich bibliographic notes, and a set of exercises to drive home the major points of the chapter.

Commentary

Cargill's insights and programming practices are of great value to novice and experienced C++ programmers alike. This is the best book I have found to help me develop my C++ programming practices.

When reviewing a technical book, some considerations are: is the book's subject matter useful and relevant, is the book organized in a logical and useful manner, and is it easy to understand what the authors says. C++ Programming Style rates high on all three qualities. The subject matter of C++ Programming Style is highly relevant for today's C++ programmers. As proof of the timeliness of the subject matter, many published programming examples demonstrate the weaknesses that Cargill discusses. After reading this book, you will understand ways to improve most all of the C++ code you see.

The book is organized so that each chapter is a separate lesson on a specific C++ programming concept. Chapters build upon concepts taught by previous chapters, but as Cargill touches on these concepts, he carefully and thoroughly references them so the reader can review the concepts, if necessary.

Cargill's writing style is comfortable and articulate. The book requires active mental participation on the reader's behalf, but is still very easy to read and understand. In a technical book of this size with this many examples, it is not unusual to find a couple of typographical and/or technical errors. I found no errors in this book.

While the subject matter, organization and implementation of this book are all excellent, the greatest strength of the book is a result of Cargill's programming experience and sound advice. Cargill does not get caught up in fashionable uses and abuses of C++. When Cargill uses or decides not to use a specific C++ programming construct, he clearly and persuasively explains his reasoning. For example, in the chapter on multiple inheritance, Cargill unmasks illegitimate uses of multiple inheritance, even though multiple inheritance is currently the rage in many C++ circles.

Conclusion

About once every other year I find an especially helpful book that I read, keep, and use. This is one of those books. C++ Programming Style is one of the most useful books about C++ programming that I have seen. It addresses issues that are relevant to both inexperienced and experienced C++ programmers. The book has a good organization and is well written. I highly recommend this book to those interested in developing good C++ software.

Title: C++ Programming Style
Author: Tom Cargill
Publisher: Addison-Wesley
One Jacob Way
Reading, MA 01867
Price: $24.75
ISBN: 0-201-56365-7