Hell is other People's Code
I used to be a coding standards fascist. There, I've said it. Time was when I would roll my eyes in despair at other people's code, and work late into the evening rewriting and reformatting it. Not enough whitespace, no proper indentation, naming conventions not being followed! Not enough comments!
Then I mellowed out. I came to realise that I wasn't being like this for the good of the team, but because it was an easy way for me to "ride the code" - i.e. ritually mount the code like a male chimp showing his dominance. Y'see, I had to determine all the standards - bascially people had to write code that made it look like mine.
I've locked horns with similar people, and you wind up with a "standards showdown", where neither side is willing to back down: "No, the first curly brace goes on the same line as the construct!"
So what do I advocate? I don't disagree with standards, I think they're important. What I don't like is people using them as a weapon so they can ride you like a monkey around the office. So I'm not going to advocate anything, but suggest a few things to ponder over:
- Standards can be a bit like an ancient religious text: the laws contained within were created to solve specific problems at a point in time, but things move on: problems and opinions change; don't create a standards doc that everyone turns to for guidance, or you'll wind up with people who follow it slavishly but fail to understand why, other than it's in the standards;
- MS have defined standards already and supplied a tool (FxCop) to allow you to analyse your code; this gets round the trap of having a single person dictating standards; there are other tools that let you control the whitespace and layout of your code, but I don't get too hung up on all that; as long as it's readable and well-factored you shouldn't need to be riding people about spaces between operators;
- Code should be readable and self-documenting; too many nested regions & too many inline comments add "noise" to the code & make it hard to read and understand; methods, like classes, should be small and serve a specific purpose - the name of the function should document what it does so that readers scanning through your code can work out what's going on quickly (provide comment headers to give more detailed information; use NDoc to compile up your comments);
- Like Fowler, I believe strongly that if code has inline comments, it's not done yet; in other words, if you need comments within your method, it indicates that it needs refactoring - the method should do one thing only, not several, which pretty much obviates the need for inline comments;
- Collective code ownership is one thing, but you need to ensure that the pursuit of uniform code doesn't stifle creativity or lead to mediocrity.
'nuff said.

0 Comments:
Post a Comment
<< Home