At different times in the past I’ve either agreed with or fought the application of coding standards. Recently, I’ve been looking at the subject again. In a wonderful case of timing I stumbled across an ad in CUJ (10/2004) for CodingStandard.Com. They have a coding standard for C++ that seems to cover much of what I was looking for.
Later in the same issue, the Sutter’s Mill column had some more advice from the upcoming book C++ Coding Standards by Herb Sutter and Andrei Alexandrescu. In this column, they suggest not standardizing personal preference issues (indenting, brace placement, etc.).
This lead me to a useful concept that I need to explore further. What I’ve normally called a Coding Standard is actually two documents.
- Coding Standard
- This document covers the rules that increase quality and maintainability of the code. This includes subjects like when to
throw
exceptions and the usage of RAII. Most of the items that we call Best Practices fit here. - Style Guide
- This document establishes style preferences to reduce incidental differences in the code. This includes brace placement, indenting, CamelCase vs. underscores, etc.
The important point is that most of the religious debates I’ve seen fall into the second document. Additionally, most of the stuff in the second document is a matter of preference, there is very little evidence that one style is significantly better that another. On the other hand, the items in the first document are usually demonstrably better than their alternatives.
By separating the two documents, we might be able to get two major benefits:
- Don’t avoid the best practices because you don’t like the style of the second.
- Allow the styles to change as needed without invalidating the standards.
This division also better reflects the purpose of the two sets of rules.