In the last couple of weeks, I ran over some posts about c# coding style guidelines, i.e. guidelines about how to arrange (style) your code. This normally includes things like where to put paranthesis, how fields are named (e.g. with/without _) and so on.
All these posts (no I don’t have the links anymore) had two things in common:
- all were just paper tigers: no tool support, the rules have to be checked manually
- all were different, with no real explanation why code should look as they say
The reason why I’m astonished about these posts is that there exists StyleCop. A tool that checks c# code against a large set of style rules.
Only with a tool, we can guarantee that there are really no violations in our code. A manual approach with reviews will never give the same quality result.
Now, you may argument about the rules provided by StyleCop, but face the facts that these rules are at least provided with an explanation (StyleCop.chm) and not just based on a personal style.
We’re using StyleCop for several (> 10) months now. My experience is that it really supports us in writing code that is much more readable, especially if reading code from a fellow software developer.
To get a painless StyleCop experience, we use ReSharper from JetBrains (Visual Studio Add-in: refactoring, code navigation) and StyleCop for Resharper (ReSharper plugin: visualizes StyleCop violations in real-time in code editor, automatic correction of a lot of violations).
And as final words: don’t start switching off StyleCop rules, stick to the standard (default).