Live data from Hacker News

Why is 80 characters the 'standard' limit for code width?

programmers.stackexchange.com

11–20 of 46 posts

Re: Why is 80 characters the 'standard' limit for code width?

#11
post #3

Back in the day, I used punch cards in college computer courses. Languages like FORTRAN, COBOL, and assembler were column dependent, e.g. Col. 1 : Blank, or a "C" or "*" for comments Col. 1-5 : Statement label (optional) Col. 6 : Continuation of previous line (optional) Col. 7-72 : Statements Col. 73-80: Sequence number (optional, rarely used today) With the sequence numbers if you dropped the deck and scrambled the…

I never bothered with sequence numbers. Boy was it a joy to put your card deck in the reader and wait at the self serve printer, and have your program compile, run, and produce the correct output the very first time !

Re: Why is 80 characters the 'standard' limit for code width?

#12
post #7

80 characters is also comfortably within the limits for presenting code in most books, except for pocket reference sized books. The actual limits for most books are about 85 characters, so that leaves some leeway. Even if I have the screen real estate, I don't think I'd want to intentionally write wide code, and I like self-explanatory names. On a 4k screen I might like Eclipse layouts that put the logging next to th…

60 to 90 characters per column is widely used in typesetting for good readability. It’s probably not a good idea to go very far beyond 80 characters or so purely for readability, no matter the context.

Re: Why is 80 characters the 'standard' limit for code width?

#14
post #13
post #6

Java programmers have variables longer than 80 characters now a days.

As a primarily Java programmer, those folks need to be drawn and quartered.

Don't go near Cocoa (/Touch) developers. You will be overtaken by rage.

Re: Why is 80 characters the 'standard' limit for code width?

#15
post #10

IME, there is a very strong correlation between good developers and short lines. Bad devs doesn't mind if some lines are 150+ chars long and require horizontal scrolling. They also don't care that much about consistent naming of symbols or having correctly indented code. There are very strong reasons for keeping your lines short, naming consistent and indentation in check. But at the end of the day, you either "get"…

For me those things are almost like a book cover. If I open a file and I see freakishly long lines I just assume that the content will be not well crafted.

Re: Why is 80 characters the 'standard' limit for code width?

#16

While the initial reason may be historical, I've found that on smaller monitors 80 character width makes it just about wide enough to have two code windows side-by-side. That's why I usually tend to stick to that limit. Though on bigger monitors I often stick to 100.

80 or 100 is both fine, but I prefer 80. Shorter lines are simply easier to read.

It just like reading a text online. Most people would prefer shorter lines, compared to one extremely long one. It's simply easier to keep track of where you are.

Re: Why is 80 characters the 'standard' limit for code width?

#17
post #6

Java programmers have variables longer than 80 characters now a days.

Which is why when you see a codebase like Plan 9/9front's, you can't help but be in awe.

Most of their lines are incredibly compact. In fact, a lot of people who first read the code suffer a bit of a culture shock. It's just too... simple, and readable. Especially for C. This causes some to knock their own particular style of ANSI C as inadequate.

I think it's a testament to their genius. You'll probably never find a codebase as massive yet as readable and grokkable as theirs. If you're used to modern Linux code that copiously uses glib, D-Bus and a whole bunch of other libraries, you'll either find it a huge breath of fresh air, or completely blasphemous.

Re: Why is 80 characters the 'standard' limit for code width?

#19
post #4

It's funny to start seeing more and more questions from people who started using computers with Windows 95. Actually, not it's not, little punks making me feel old, get off my lawn.

Hey.. I still remember my first programming experience with Turbo Pascal running with MS-DOS 5 and I didn't know how this 80 characters per line popped up in history. I remember there was something like .. "MODE CON..." that I could change the chars, but I didn't know why and how the defaults were settled everywhere the same. Kudos for the OP asking this question.

Re: Why is 80 characters the 'standard' limit for code width?

#20
post #13
post #6

Java programmers have variables longer than 80 characters now a days.

As a primarily Java programmer, those folks need to be drawn and quartered.

Haha I am also a Java programmer. To be honest, I try and keep things as brief as possible, but I almost never sacrifice readability for brevity. So, I'll admit, some of my variable names get a bit lengthy at times; however, that is for all languages I program in, not just java.
Post reply on HN