8 ms·
80 characters is an accident of history, an accident that should be corrected. With an 80 character limit, you need to be mindful of the length of your identifi
by kstenerud 14y ago
80 characters is an accident of history, an accident that should be corrected. With an 80 character limit, you need to be mindful of the length of your identifiers. You start compromising recognizability in the name of fitting the line to an essentially arbitrary length (drop a few vowels, maybe use a less precise word).
Using a width limit to coerce into indenting less is just plain silly. If you don't want high levels of indentation, put THAT in your coding guidelines. Don't rely on side effects.
- GhotiFish 14y agoThis isn't about the indentation. Look at the examples. you can see that allot of his code is indented heavily. This is about the amount of time and distance required to scan my eyes across a line to understand its meaning. How much do I have to read to understand a simple concept? This is also about the amount of screen real-estate i have to use. We arn't programming on VT100 terminal any more, damn right. NOW I get to have the compiler output and continuous integration output to my left. The directory, class structure and documentation to my right. I also get to split my screen to have two editors open for comparing snippets of code line by line. Merge conflicts and diffing are hugely common operations. merges have three parallel windows open at once! You, still, only have 80 characters to work with.
- ajanuary 14y agoThis isn't about the indentation. From TFA: Also, having the mandatory indentation whitespace increase the line width is a good visual way of minimising the nested loops in your code and suggesting, in a subtle way, to refactor anything that is indented more than about four times.
- rdtsc 14y ago> 80 characters is an accident of history So are many useful inventions. The reason it matters is readability. News papers for example have been using columns for readability and to me that makes it easier to read. Having the same for code is great. I have 3 vertical monitors so I want to have as much of the code go vertically and then I split the monitor into 2 or 3 columns (vertically), I find I get much better productivity, and my eyes get less tired. I like scanning up and down not too far to the left of right. I have not always followed this and looked at some old code with 160+ long lines in some places. Besides terminals are still used when logging in via SSH into a server it is still nice to not to have to keep re-sizing the terminal according to whatever the largest line is.
- UnFleshedOne 14y agoI don't think long lines that are broken in the middle at 80 characters are more readable than single line that goes to slightly more. Readability in code is not about having a pleasantly looking paragraph (paste some code into MS Word and see how readable it is). Readability is about conveying logical structure through form. A statement is in one line because it is doing one thing.
- jdbernard 14y agoNo, but long lines that are broken intelligently so as to fit in an 80-character wide space are easier to read than a single line. MyObject object = MyObjectBuilderFactory.getBuilder().essentialProperty("the value").otherImportantProperty(42).specialThingyReference(someVariable).build(); vs MyObject object = MyObjectBuilderFactory.getBuilder(). essentialProperty("the value"). otherImportantProperty(42). specialThingyReference(someVariable).build(); Or how about: cookies = responseObject.headers.findAll { header -> header.key == "Set-Cookie" }.collect { cookieHeader -> new Cookie(cookieHeader) } vs cookies = responseObject.headers.findAll { header -> header.key == "Set-Cookie" }.collect { cookieHeader -> new Cookie(cookieHeader) } Just because it is one statement does not mean it has to be on one line.
- 14y ago
- kps 14y ago“80” is an accident of history, but “around 80” is not; it's a product of centuries of experience with reading.
- __del__ 14y agoGrab a novel. I bet the line width is closer to 60 characters. Horizontal scanning is hard on the eyes.
- snprbob86 14y agoLuckily, most code is indented 1 to 4 levels at 2 or 4 spaces per indent. This means that typical code width is limited to be anywhere from 78 to 64 characters wide. That's 77 to 63 if you're actually going with 79 characters, which is what PEP8 et al suggest. Much closer to the 55 to 65 characters of the two or three books I just checked.
- kps 14y agoYou're quite right. The ‘accident’ of 80 comes from the ability of a typewriter to space into what were usually margins.
- fakeer 14y agoIt is the hjkl of line length.