Live data from Hacker News

Line length in programming

ck.kennt-wayne.de

11–20 of 74 posts

Re: Line length in programming

#11
Here is what I've said about 80 char in the past.

"If the argument for expanding to 100 or more is that screen is getting wider, then the benefit of wide screen is the ability to fit multiple terminals in one window. For normal workflow, I'd split my windows into two or terminals, depending on what I am doing, so I don't see any benefit in increasing the limit."

Re: Line length in programming

#12
post #8

In my opinion the 80 character limit is mostly for better presentability. If the code appears in a blog post or a book, it is better to read and typeset if it is less than 80 characters. Though there are several articles[1] which explain other reasons for this legacy limitation. I would be happy to read code more than 80 characters, if it doesn't have to be artificially cut into multiple lines (the screenshot in the…

IMO, given that most blog templates include copious margins, many don't allow readers to resize the text, and some don't even allow readers to scroll horizontally, 80 characters is far too long for a line of code in a blog post.

Re: Line length in programming

#14
I'm surprised and, to some degree, annoyed at the superficiality of some of the arguments in this debate. Like this one:

> Readability - You don't have to scroll over horizontally when you want to see the end of some lines.

It's not having to scroll horizontally that bothers me with long lines. My monitor is wide enough that it can probably hold 250 characters with ease. It's having to read long lines. Something is very bloody, terribly wrong in your code if you consistently find you need to write 150-character lines.

Besides, yes, monitors have gotten that wide that it's not an issue. Is there any serious reason to assume that code is the only thing I want displayed on my monitor at a given time? In a single window? That's as big as the monitor? The only moment when people had a good reason to be enthusiastic about that was the late 70s, when serial terminals appeared and teletypes began going the way of the dodo.

Also, who says the IDE is the only place where I want my code to be output? Maybe I want to grep on it or whatever. On an 80x25 terminal window because the least useful thing on earth is a huge monitor where I constantly alt-tab between a full-screen editor and a full-screen terminal.

Re: Line length in programming

#15
post #5

80 is too few. The old reason for it (what if you get stuck doing an emergency bugfix using vi on an 80 char display?!?) no longer holds. It's not massively too few, and most lines never get close to the limit anyway, but the odd line of 100-120 thrown in really isn't a problem on a modern display.

I thought the historical reason was that punch-cards had 80 characters per line.

...just Googled it: http://programmers.stackexchange.com/questions/148677/why-is...

Re: Line length in programming

#16

I'm glad we talk about this. Once we have solved this question we can move on to really important stuff, like tabs vs spaces.

Code is read far more than it is written. Therefore code legibility is important. Line length affects code legibility. Therefore line length is important.

Re: Line length in programming

#17
In Vim:

    set textwidth=80 colorcolumn=+1
Then you get a coloured column 81 (probably red).

For some things I use colorcolumn=+1,+21 for highlighting 81 and 101, for situations where I allow myself 100 in an extremity.

Re: Line length in programming

#18

80 chars is a useful rule of thumb, so long as it's tempered by practicality. I've worked on projects where the limit was taken far too literally, which results in code that's harder to read. This is especially true if you're using something verbose (Java, Objective-C) or whitespace-sensitive (Python).

Bingo. To quote Captain Jack Sparrow, style guides are "more what you'd call guidelines than actual rules".

They're not a substitute for common sense, and sometimes breaking the rules is for the greater good. I find the similar situations in shops that enforce strict naming conventions.

edit: The other tip is that the 80 character limit is closely aligned to the optimal line length for regular reading: http://ux.stackexchange.com/questions/3618/ideal-column-widt... A bit more than normal is allowable for programming because of indentation and the more structured nature of the text.

Re: Line length in programming

#19
post #11

Here is what I've said about 80 char in the past. "If the argument for expanding to 100 or more is that screen is getting wider, then the benefit of wide screen is the ability to fit multiple terminals in one window. For normal workflow, I'd split my windows into two or terminals, depending on what I am doing, so I don't see any benefit in increasing the limit."

Please take the time to review and correct this sentence next time you copy-paste. This is a painful read.

Re: Line length in programming

#20
post #11

Here is what I've said about 80 char in the past. "If the argument for expanding to 100 or more is that screen is getting wider, then the benefit of wide screen is the ability to fit multiple terminals in one window. For normal workflow, I'd split my windows into two or terminals, depending on what I am doing, so I don't see any benefit in increasing the limit."

I quite like 100 chars: it's perfect for two side-by-side windows on my screen. (i.e. two adjacent emacs buffers are about 101 chars wide each.)
Post reply on HN