3 ms·
Its mostly tribal knowledge at this point built on the echo of “studies show 80 is the best for comprehension and understanding” 80 should be fine for most sin
by kingkongjaffa 3y ago
Its mostly tribal knowledge at this point built on the echo of “studies show 80 is the best for comprehension and understanding”
80 should be fine for most single lines of good code in most languages.
Comments can usually be longer so I have my linter ignore comment length.
Some discussion here: https://stackoverflow.com/questions/578059/studies-on-optimal-code-width https://stackoverflow.com/questions/578059/studies-on-optima...
For me it’s one of those things without a “scientific” answer, but the status quo is good enough that it’s easier to just go with it and never think about it again. Like linting and autoformatting, tabs vs spaces, all trivial stuff that detracts energy from building a product for customers.
- KronisLV 3y ago> 80 should be fine for most single lines of good code in most languages. It feels like what's doable in one language, might be a bit more restrictive and annoying to follow in another one. For example, Java, when written in an idiomatic way, with verbose variable names etc.
- DrBazza 3y ago> 80 should be fine for most single lines of good code in most languages. C++ with even a modest template will flow over 80 without much effort. I'm now using the condensed width font Iosevka font [1] with 160 chars as my max width in clang-format and indents at 1. After a few days of using it, I'm converted. It was a bit odd looking at first, but I guess that's brain plasticity at work. 1. https://github.com/be5invis/Iosevka/releases https://github.com/be5invis/Iosevka/releases
- joshka 3y agoI've written a lot of code in a lot of different languages and have preferences for each that are based on the general type of code that tends to be written. E.g. what length are the identifiers and standard function names, what is the standard spacing, how are idiomatic language features used. My subjective opinions on a few of them: Java I find works well with a soft 100, hard 120. The language and library tends to prefer and encourage longer class and function names, and these are often repeated multiple times in a single line. C# seems to work well with 100. Rust I find well works with 100, and this is the default out of the box format for rustfmt. Javascript (especially with 2 spaces) works well with 80 characters. When writing code for documentation sites (e.g. https://ratatui.rs/tutorials/hello-world/ https://ratatui.rs/tutorials/hello-world/), often the code block fits in an area which is surrounded by prose with a width optimized for reading. The resulting width of the code block tends to be ~80 or less. It's worth making this tweak to your formatting for such example code.