1/10/2018 - 11:34 AM

A word on line length in code

A word on line length in code

A lot of coding standards have an opinion regarding line-length. Some often recuring lengths are 80 and 120 characters.

It is commonly stated that the 80 character limit original existed because of terminal screens. Since we don't live in this world anymore, the 120 character limit becomes more and more the standard.

This statement isn't entirely correct, that is to say, it's even worse than that. The common coding standard is a result of the IBM's 1928 80 column punched card format.

source: http://softwareengineering.stackexchange.com/questions/148677

There are, however, other reasons beside punchcards, terminals and screen size that come into play.

It turns out that the subconscious mind is energized when jumping to the next line (as long as it doesn’t happen too frequently, see above bullet point). At the beginning of every new line the reader is focused, but this focus gradually wears off over the duration of the line (“Typographie”, E. Ruder).

In order to avoid the drawbacks of too long and too short lines, but still energize your readers and keep them engaged, we suggest keeping your text within the range of 50-75 characters per line.

source: http://baymard.com/blog/line-length-readability

Besides this, code is not just displayed in the Editor, it is displayed in Diff-tools, (browser based) code review tools, emails, bug trackers, etc. People with laptops with small screens will work on the same code-base as user with "broad" screens.

Wider lines means more scrolling in a lot of such tools as "line-wrap" is not universally implemented.

When stating "120 works for me", effectively you are not taking other scenario's into account than your current working scenario. It is basically a poorly disguised

There is a difference between code, markup and generated output. For code the 80-ish (50-75 characters + indentation whitespace) is more important than for markup, as code is more frequently read and updated than docs.