Monday, August 29

More Good from Tim Bray: Ken Arnold on coding style

In an October 2004 article called Style is Substance, Ken Arnold (a former Sun illuminatus with some seriously impressive credentials) details his somewhat heretical stance on coding style: it should be baked into the grammar of the language. And I agree.

Some background for the non-coding readers out there: the programs that turn the gibberish people like me actually type into files that computers can execute are called compilers. Compilers are incredibly picky about most aspects of the syntax they understand; you must match every '{' with a '}', you must end lines with a ';', you must name the file according to this scheme, et cetera et cetera. The variations they do allow are collectively referred to as "style", and us programmers tend to spend a relatively large amount of time arguing about it.

The fact that we do spend so much time arguing about it is indicative that it's at least important enough to argue over, even if it's totally unimportant to the compilers. Inconsistent style is a major, major, problem for code readability (by humans), and it tends to hide logical errors (the kind where what you told the computer to do is a valid thing from its perspective, it's just not what you want). By baking a 'style' specification into the language, not only do you end the argument once and for all but you force people who had inconsistent style to standardize. There's a big code-quality win right there.

Of course, you could argue that this is a solved problem, and that most modern IDEs already provide on-the-fly style adjustment so that it doesn't really matter what gets put into the text file because your editor can display it according to your particular preferences. In fact, I suppose I just did. But hey, at least he got me thinking about it.

No comments: