This site will look much better in a browser that supports web standards, but is accessible to any browser or Internet device.

Anomaly ~ G. Wade Johnson Anomaly Home G. Wade Home

November 21, 2004

Review of C++ Coding Standards

C++ Coding Standards
Herb Sutter and Andrei Alexandrescu
Addison-Wesley, 2005

For many programmers, the term coding standard generates a gut-level response. We all know that someone is going to be pushing the one, true brace style or the proper way to indent code. This subject is probably the best way to generate instantaneous rebellion among a group of programmers.

The first "standard" in C++ Coding Standards wipes all of that away with their first rule:

0. Don't sweat the small stuff. (Or: know what not to standardize.)

In one quick entry, Sutter and Alexandrescu sweep all of the indent-level, brace-placement, CamelCase/underscores holy wars into a single category and give a useful bit of advice: Be consistent. The authors point out that any professional programmer should be able to read and write in any of these styles. The differences are basically a matter of personal preference.

From this point on, we get to see a coding standard that is focused on best practices and proven techniques for improving code. Almost every item is explained with examples. Some have exceptions, with an explanation of when (and if) the exception should override the rule. All of the rules contain references to other sources to read for further explanation,

The rules cover such general topics as 1. Compile cleanly at high warning levels and 3. Use a version control system to specifics like 73. Throw by value, catch by reference. Some of the items could be considered common sense if it weren't for the fact that I've seen them regularly violated by people who claim to be professional. Others are based on knowledge of the language and implementation details that most of us never need to care about.

There are even a few rules that violate my personal list of "best practices." Like all of the others, the advice in the book is authoritative enough and backed by good reference. So even on the issues that I disagree with, Sutter and Alexandrescu argue their case well enough that I plan to go back and reassess my views.

If you are a new C++ programmer, this book will help you learn to be a much better programmer. If you are an experienced programmer, this book will help improve your skills and give you a reference to use to help keep more junior programmers in line. If you manage C++ programmers, this book is a good starting point for a coding standard to improve the work of all of your programmers. I don't think I can recommend this book too highly.

Posted by GWade at November 21, 2004 09:58 PM. Email comments