Continually experimenting with new ideas and techniques — Reconstructing, Developing, Modernising.
I was looking at the Elm Style Guide and this good vs. bad comparison struck a nerve which made me consider a small loosely held prejudice of mine:
With the justification for this preference including: If we ever add a new field to Circle that is longer than radius we have to change the indentation of all lines, leading to a bad diff. Furthermore, ending lines with a comma makes diffs messier because adding a field must change two lines instead of one.
I find the , hanging in mid-air a little odd looking, it’s too small of a symbol to live by itself in my mind; in English text it is usually butted up against the previous word.
At the moment my English heritage leads me to prefer to end lines with a comma, and my preferred languages (think Ruby or Perl) let you have an “extra” , at the end of a list so you can write code in a style which allows for easy reordering / addition / deletion of lines (and I know this might not be legal elm):
Usually in my Ruby code this type of thing would be in a hash initialisation, so I might not care about the ordering except for “cosmetic” reasons. In other circumstances in other languages the ordering might be vital (e.g. it might determine memory layout in a structure), so a casual reordering could have big consequences.
A similar thing comes up with method calls in Ruby when you spread them over many lines. As people have started moving the . for chained method calls to the beginning of the next line, all of a sudden it becomes much harder to paste code into a REPL – compare these examples typed a line at a time into irb:
At least here the . abuts something else, so I’m not so disturbed by the aesthetics of either.
Once an operator has a little more “ink” to it, like Elixir’s |> then it seems reasonable to have it sitting the beginning of a line.
A lot of my prejudice comes not from any well formed aesthetic foundation or from the results of psychological studies, but from how well my tools of choice (e.g. vim) handle the code. Once the in-editor indentation and automated code formatters/style-checkers work properly then I’m happy to work with any style and am sure I’ll get used to it in time.
It is funny how little details cause disproportianate reactions 😀