Due to a peculiar set of circumstances I’m looking at C# coding standards or style guides. The key decision is to agree to a style guide that everyone more or less follows. I also like style guides that go a bit beyond how to format the curly braces on a newline or tabs versus spaces. I like rules like this:
Define small classes and small methods.
— Rule #69 The Elements of Java Style
At a previous organization:
- I bought a bunch of copies of The Elements of Java Style.
- I handed them out to all of our developers.
- I ran a brown bag lunch covering the top 10 rules I wanted them to concentrate on.
- We checked most of the style items in the continuous build with Checkstyle. Gentle enforcement.
A quick perusal of the C# world says there isn’t any base coding standard like Sun’s Coding Conventions. I’m a bit surprised since I expected Microsoft to have at least attempted to do so, but other than the things you can glean from heaps of example code it doesn’t appear they have a well documented default.
The candidates from fifteen minutes of googling appear to be:
- C# Coding Style Guide from icsharpcode.net.
- The iDesign C# Coding Standard. from iDesign.
- C# Coding Standard from Philips Medical Systems.
The ic#code standard is concise and covers the basics. The iDesign option is more comprehensive. A quick skim did found a rule I don’t agree with:
Avoid methods with more than 200 lines.
Two hundred lines is ripe for refactoring to many 10-20 line methods. Still it is a lot more in depth. The final Philips standard attempts to combine rules from their C++ Coding Standard, the ECMA C# language spec, and an MSDN Design Guidelines Library Development document.
I’m pretty open at this point to suggestions from any of you who have spent a lot of time in the C# trenches.