Coding standards, Coding rules, Coding guidelines, etc...
If there's one thing that developers usually just cannot (or will not) agree to, then it's Coding standards/rules/guidelines or whatever name you want to give it. I posted a short item about a new tool from Microsoft that checks if your code matches the Microsoft guidelines and sure enough, I'm already getting mails on the subject explaining that Microsoft's rules suck and that they use one that's better. I thought it might just be a great subject for a discussion. But let me share my views on the subject first.
Coding standards, my view
I've been working as a developer in various roles and projects now for over 20 years. Yes, I'm that old, but it's to show that I speak from experience on this subject. Each project I worked on has had one or another form of coding guidelines or standards. In one project, they even called it a coding convention in an attempt to make it more important. My reaction in most occasions was: "What ever..."
The thing with this subject is, that developers simply cannot agree to one single guideline. Every developer thinks he/she is the best in his/her area and therefor the expert to tell others how to write their code. Well, they're wrong.
A coding standard is as good as the method to enforce it. If it's not enforced, then it's useless. And in 99% of all projects you will see that coding standards are not enforced. In my view, the only standard that works is the standard that you can enforce using tools. The guidelines checked by Microsoft's FxCop are a good example. It always uses the same rules for all code and always warns in the same way. There are other tools that do that as well, like DevPartner from Compuware. You can agree to those rules or not, but at least it leaves little room for discussion and I see FxCop being more and more accepted.
And now there's StyleCop. It checks your code against the coding rules as used at Microsoft development centers. Again, you can discuss if these rules are correct, but you get a tool that validates the code and tells you were you have strayed from the narrow path. My feeling is that although I don't entire agree to all rules, at least I can force my team to stick to these rules. Simply by breaking the build if they don't comply to the coding rules.
There are tools that allow you to write your own custom rules, like ReSharper and DevPartner. Useful as this can be, what do you do with code generated by Microsoft code generators. Think only of generated code for DataSet objects and WinForms. It's highly unlikely that this code will adhere to your guidelines. But will the use the Microsoft guidelines? It's a better bet then with your custom rules.
Another misconception is that these rules improve the quality. But to be frank, this is mostly bullshit. The rules checked by FxCop (and similar tools) check for code quality with respect to the use of the .Net framework. StyleCop (and similar tools) check for style issues. But that does not improve code quality. That can only be achieved by testing your work and using defense programming techniques. But I digress.
So whatever suits you, I guess. I'll stick to using the Microsoft Guidelines and use their tools to check if I've done it right. But whatever coding standard you choose, make sure your entire team sticks to those rules, otherwise they're completely useless. Unless it's to satisfy management that you thought about code quality.
But please, feel free to comment. I will approve them as soon as possible, but with the weekend starting in the Netherlands it might take some time. But I'd love to hear how the community feels about coding standards, the new Microsoft tool, and other things regarding this subject.