Stop Trying to Express Yourself With Code Layout
But I Want To

2017-01-11

Slug   ignore

Allowing programmers to express themselves through their choices about notation layout – the fiddly details of how a program represented as a string of characters is laid out in a text file – provides flexibility for different preferences and computer screen situations at the expense of mutual readability between different people.

Strict Enforcement with a Human Touch

Programs that reformat source code to enforce style guidelines have tense relationships with their victims users.

The hindent Haskell formatter does some things that I could live without. Here's an example I was recently frustrated with:

newtype Flip f a b = Flip { runFlip :: f b a }

was turned into this,

newtype Flip f a b = Flip
  { runFlip :: f b a
  }

Subjectively, I find the latter ugly (I think, in part, because I've accepted both K&R and OTBS curly-brace styles into my heart, and this is neither). Objectively, it's problematic when working with a small screen. This kind of formatting reduces the effective vertical height of a monitor to a third of what it could be!

But there is good reason for doing things this way: identifier changes are less likely to necessitate a different approach to line-wrapping. Such layout changes arguably make diffs harder to read, so avoiding that situation altogether is a valid defensive strategy.

I like code formatters because reading and navigating code written in a consistent style is definitely easier. Even in my own world of personal code I like them because it means I don't have to get every single whitespace just right, the formatter will clean up after me (e.g. perhaps my style includes a space before a closing square bracket, but I left one out when editing).

I'd say that the right thing to do is to use a formatter that meets your needs (and wants) when reading and editing code, then run another formatter when committing to a shared repository. The unfortunate aspect for Haskellers is that hindent recently removed support for multiple styles. None the less, getting involved in a project that does use a mechanically enforced style means that you can use your own forked hindent when working, secure in the knowledge that the project's chosen formatter will make it look like you agree with your colleagues' questionable taste!