3 ms·
Come for punchcards, stay for legibility. 80 characters per line is an odd convention in the sense that it originated from a technical limitation, but is in fa
by strogonoff 11mo ago
Come for punchcards, stay for legibility.
80 characters per line is an odd convention in the sense that it originated from a technical limitation, but is in fact a rule of thumb perfectly familiar to any typesetting professional from long before personal computing became widespread.
Remember newspapers? Laying the text out in columns[0] is not a random quirk or result of yet another technology limitation. It is the same reason a good blog layout sets a conservative maximum width for when it is read on a landscape oriented screen.
The reason is that when each line is shorter, the entire thing becomes easier to read. Indeed, even accounting for legibility hit caused by hyphenation.
Up to a point, of course. That point may differ depending on the medium and the nature of the material: newspapers, given they deal with solid plain text and have other layout concerns, limit a line to around 50 characters; a book may go up to 80 characters. Given a program is not a relaxed fireside reading, I would place it closer to the former, but there are also factors and conventions that could bring acceptable line length up. For example, indentation and syntax highlighting, or typical identifier length (I’m looking at you, CNLabelContactRelationYoungerCousinMothersSiblingsDaughterOrFathersSistersDaughter), or editor capability to wrap lines nicely[1].
Finally, since the actual technical limitation is gone, it is actually not such a big deal to violate the line length rule on occasion.
[0] Relatedly, codebases roughly following the 80 character line length limitation unlock more interesting columnar layouts in editors and multiplexers.
[1] Isn’t the auto-wrap capability in today’s editors good enough that restricting line length is pointless at the authoring stage? Not really, and (arguably) especially not in case of any language that relies on indentation. Not that it could not be good enough, but considering code becomes increasingly write-only it seems unlikely we will see editors with perfect, context-sensitive, auto-wrap any time soon.
- Xss3 11mo ago80 chars per line was invented when languages used shortened commands though. Nowadays 120 is more appropriate. Especially in Powershell. Not so much in bash where commands are short, 80 can stay alive there!
- strogonoff 10mo agoI think it does depend on language and typical identifier length, but I would say what I work with deserves 80 characters. If I was writing Swift for Apple ecosystem, I might go wider.
- PaulDavisThe1st 11mo agoWhen I read text I prefer it to use the lessons of typography and not be overly wide, lest my saccadic motion leads my immersion and comprehension astray. However when I read code I do not want to scan downwards to complete the semantics of a given expression because that will also break my comprehension and so when a line of code is long I'd prefer for it to remain long unless there are actually multiple clauses and other conditionally chained semantic elements that are more easily read alone
- iknowstuff 11mo agooof this looks awful on mobile, with extra line breaks
- PaulDavisThe1st 11mo agoI don't know any way to force line breaks on HN without extra line breaks ... do you?
- deleted 11mo ago[deleted]
- deleted 11mo ago[deleted]
- strogonoff 10mo agoYou can’t do it unless you can place linebreaks differently according to everybody’s screen width. This is a good illustration of why 80 character rule works; then everyone’s screen would be at least 80 character wide.
- naikrovek 11mo agoI’m very sure this is a myth. Like any good myth, it makes sense on the surface but holds zero water once you look close. Code isn’t prose. Code doesn’t always go to the line length limit then wrap, and prose doesn’t need a new line after every sentence. (Don’t nitpick this; you know what I’m saying) The rules about how code and prose are formatted are different, so how the human brain finds the readability of each is necessarily different. No code readability studies specifically looking for optimal line length have been done, to my knowledge. It may turn out to be the same as prose, but I doubt it. I think it will be different depending on the language and the size of the keywords in the language and the size of the given codebase. Longer keywords and method/function names will naturally lead to longer comfortable line lengths. Line length is more about concepts per line, or words per line, than it is characters per line. The 80-column limit was originally a technical one only. It has remained because of backwards compatibility and tradition.
- strogonoff 10mo agoFinding the start of the next line is a challenge universal to both code and prose, and the longer the line the harder it gets, regardless of how good your vision is. I acknowledged that there are other factors with code (such as indentation or syntax highlighting), which is why 80 characters—wider than either newspaper or book—makes sense, unless your typical identifiers are really long.
- justsomehnguy 11mo ago> It is the same reason a good blog layout sets a conservative maximum width for when it is read on a landscape oriented screen. Except 99.9% of times it's becomes 50 characters with 32pt font which occupies ~25% of the horizontal space on a 43". "Good" my ass.
- strogonoff 10mo ago50 characters is perfect as far as I am concerned…
- UltraSane 11mo agoThe 80 char max line width convention makes no sense with modern monitor resolutions and ultrawides being very common.
- strogonoff 10mo agoPut 3, 4, 5 files side by side and enjoy.
- int_19h 11mo agoThe right answer to this is that IDEs should wrap lines automatically according to the actual dimensions of the editor, but they need to understand the syntax of the language they are wrapping to do that right.
- strogonoff 10mo agoYes, but no one has bothered to implement that so far and chances are no one’s going to.
- 1718627440 10mo agoExcept that were I do line breaks and how much I align the next token is a hint, how I think about the code. No IDE is able to automatically infer information, that isn't present in the input data.
- strogonoff 10mo agoThat is a good point. Linebreaks are an extra channel of meaning, sort of like body language and intonation going hand in hand with speech. Sometimes I would visually separate a short bit of code from its surroundings (and usually add a comment on top) to make it clear that it is a controversial bit that needs attention of the reader. The same mechanism applies in less extreme cases, lifting baseline legibility.
- 1718627440 10mo agoComparing it to body language is a good insight, I haven't thought of.