Writing by Peter Hilton

Enforcing coding style as part of the language

What if the compiler only accepted one coding style? 2014-07-16 #programming

Whitespace - a white desk against a bit white wall

unsplash-logoBench Accounting

I’ve come to accept that programmers will never all agree about coding style, or even a specific question such as how to use whitespace. I do find it hard to accept that this problem remains unsolved, though. Whitespace arguments probably date back to the 1960s or 1970s, and yet programmers still discuss tabs and spaces. At length.

It seems that some programmers have a (very) strong opinion about whitespace in code, but the programming languages they use never seems to enforce it. Do programming language designers really not care whether you indent with tabs, or do their indentation beliefs somehow lack conviction?

Ken Arnold stated this particular rhetorical question somewhat more strongly, in the opening essay in The Best Software Writing I: Selected and Introduced by Joel Spolsky:

… the only way to … stop worrying about style is to enforce it as part of the language. … I’m saying that, for example, the next ANSI C update should define the standard K&R C programming style into the language grammar.

This sounds like an excellent idea. If the problem of coding style, including whitespace, has a solution then surely our languages could reasonably simply refuse to compile code that violates the convention grammar. I don’t think the sky would fall.

Besides, coding is design, and I hear that embracing constraints results in better design.

Share on TwitterShare on LinkedIn