How to Get Coding Standards Right (and Wrong)
Editorial Note: I originally wrote this post for the NDepend blog. You can check out the original here, at their site. While you’re there, download NDepend and give it a try!
Nothing compares with the first week on a new job or team. You experience an interesting swirl of anticipation, excitement, novelty, nervousness, and probably various other emotions I’m forgetting. What will your new life be like? How can you impress your teammates? Where do you get a cup of coffee around here?
If you write code for a living, you know some specific new job peculiarities. Do they have a machine with runnable code ready on day one? Or do you have to go through some protracted onboarding process before you can even look at code? And speaking of code, does theirs square with elegant use of design patterns and unit testing that they advertised during the interview process? Or does it look like someone made a Death Star out of bailing wire and glue?
But one of the most pivotal moments (for me, anyway) comes innocuously enough. It usually happens with an offhand comment from a senior developer or through something mentioned in your orientation packet. You find yourself directed to the coding standards document. Oh, boy.
At this point, I start to wonder. Will I find myself glancing at a one-pager that says, “follow the Microsoft guidelines whenever possible and only include one class per file?” Or, will I find something far more sinister? Images of a power-mad architect with a gleam in his eye and a convoluted variable name encoding scheme in his back pocket pop into my head. Will I therefore spend the next six months waging pitched battles over the placement of underscores?
Ugh, Coding Standards
In this post, believe it or not, I’m going to make the case for coding standards. But before I do so, I want to make my skepticism very clear. Accordingly, I want to talk first about how coding standards fail.
Based on personal battle scars and my own experience, I tend to judge coding standard documents as guilty until proven innocent. I cannot tell you how many groups I have encountered where a coding standard was drafted, “just because.” In fact, I’ve even written about this in the past.