Closed michalmuskala closed 4 years ago
Please please don't default to over 80 chars. Any time you try to quickly look at the file in a terminal, you'll have line wraps all over the place making it unreadable. 76 is good, leaving a small margin in most cases and allowing slightly overfull lines when needed without going over 80.
Shorter line lengths leads to better reading comprehension, and shorter functions. It is also better for people with bad eyesight who tend to use larger fonts.
My vote goes for 80 as well.
I see the linux kernel is moving to 100 chars.
@alanz It's more nuanced than that:
Yes, staying withing 80 columns is certainly still preferred," notes the official commit message for this change. "But it's not the hard limit that the checkpatch warnings imply, and other concerns can most certainly dominate. Increase the default limit to 100 characters. Not because 100 characters is some hard limit either, but that's certainly a 'what are you doing' kind of value and less likely to be about the occasional slightly longer lines.'"
And they still use 8 characters tab width if I remember correctly, which might explain it. And it's C code, Erlang tends to be more succinct.
Indenting Erlang with 4 spaces is very similar to indenting C with 8 when it comes to control structures. For example in C the body of an if
is indented just once, while in Erlang the body of case
, receive
, etc is usually indented twice (once for pattern, once for body). With just 2 levels of nested case
we're talking about an indentation of 20 for the body. The code migrates really fast to the right.
@michalmuskala I never have more than two nested case
statements, preferable never more than 1 (and most beautiful is 0, and use function head pattern matching instead). 😄
The width is now configurable using the --print-width
flag.
Here is a document explaining our formatting decision https://github.com/WhatsApp/erlfmt/pull/106 on the default width of 100
And here is a document explaining formatting decisions in general: https://github.com/WhatsApp/erlfmt/blob/master/doc/Readme.md and how these documents are still open to feedback.
Today we use 92 as default line width, which is largely arbitrary.
We should experiment to see what impact line width has on the final size of real programs (in terms of LoC). The experiment would format large codebases and plot the total LoC in relation to the formatter's maximum line width. Having that data, we'll be able to make a more informed decision.