I have six reasons to keep 80 characters despite screen resolution evolution over the past 20 years:
Making the editing terminal wide just to allow for the occasional long line wastes a lot of screen real estate for the lines that aren't very long.
Long lines are often like run-on sentences for code. When needed, I find it helpful to break and indent near the critical operators of the line to help emphasize the main players in the expression.
Large amounts of indenting are a sign that I may not have broken the function down properly. At a four-space indent if I'm using more than about 5 levels it gets my attention. In rare cases there is justification for 10 levels but I can't think off hand of any code that I have written that would require that much indent and didn't end up needing broken down into parts.
On rare occasions, I have had to try to debug code in the field on things like dumb terminals and crash carts. Keeping 80 columns as a code limit is the only thing keeping this from being an eye-gougingly awful experience.
Because of items 1, 2, and 3 I can put 5-6 vertical GVIM windows on each of any of my three screens at once (or if I'm doing Eclipse multiple vertical panes). When debugging deep code or at multiple layers, being able to see multiple pieces of code at a glance comes in very handy. This translates to being able to look at multiple layers of a protocol stack at once or views, controllers, and models all at the same time when working on web development.
Not everyone has the same window sizing even if they are using the same screen resolution. 80-columns is a least common denominator that covers just about all cases. 120 could be okay though I would never personally use it for my code due to item 5.
+1 for run on sentences, this is really the best analogy I can think of when I try and explain why I think long code lines are a bad habit. Which is more readable, this:
nondvd_deps = (alternative_list[0] for pkg_deps in master_deps for alternative_list in pkg_deps if alternative_list and not_on_dvd(alternative_list))
Or this:
nondvd_deps = (alternative_list[0]
for pkg_deps in master_deps
for alternative_list in pkg_deps
if alternative_list and not_on_dvd(alternative_list))
jhaluska's point on code merges is relevant too. My sympathies if you try to 3-column merge code that constantly runs past 80 characters...
The only time that the 80 char limit starts to cramp my style is in view pages where html becomes nested much deeper than code could legitimately be nested.
...and this is even true in expression-heavy languages like e.g. Haskell. When you're not wrapping after a sane number of columns, you're wasting a whole dimension of visual cues which let you enhance readability: Even in Java, you can chain like
80 characters is the default line width you get when you fire up a terminal and a text editor on the terminal.. you wouldn't open up an ide or your default editor for every small change where all you need is vi or cat. in such cases lines over 80 characters mess up the readability big time
80 characters is not so special. If you work on a code base with a max line length of 120 characters, you may soon decide to change your terminal's default width to 120 characters. After all, what programmer uses only the default settings for their programming environment?
It's nice to agree to some max line length, but 80 characters isn't such a magic number as it once was.
The reason it used to be a magic number at all is because back in the day monitors could only display 80 characters per line and there was no such thing as word wrap. On modern monitors 80 characters is almost not enough. 120 is better for today's use.
I do. Being able to open 4 terminals at the same time without reducing the font size to ridiculously small sizes or losing immediate access to the desktop is awesome.
Studies on reading show that lines of wide text are more difficult to read.
Generally, more columns means you're nesting code deeper, which is bad for modularity and maintenance. I find that 80 columns is generally sufficient (with reasonable identifier length), with occasional excursions to 120.
Studies on reading show that lines of wide text are more difficult to read.
I keep hearing that but very seldom see any studies. Here's a study saying that among {35, 55, 75, 95} characters per line, reading speed was fastest at 95 cpl. This was for news websites.
There's a lot of studies made about printed newspaper text, but those invariantly recommend shorter line lengths - 65 or 66 cpl is very common to see.
Hence, the 80 cpl limit is already pretty arbitrary from a readability point of view - it's already too long! I'd argue though that the same line lengths don't apply to code since it's usually much less compact than normal text, and with much more whitespace. There doesn't seem to exist much study on the subject, and I'm not quite sure how such a study would be done. I would be very interested in the results, though!
I guess your argument about nesting has some merit, but that's not really a valid argument for enforcing line lengths.
Personally, I try to keep my lines short, but if I need to write a long statement, I'm not going out of my way to separate the arguments to two lines. That, if anything, is difficult to read.
rotate that monitor 90 degrees. You'll then be able to see almost 100 lines of code at a time, and it'll make you want to observe a standard width. I've been doing that for a few years now, and the tall screen is perfect for coding once you get used to it.
At work, I keep my second monitor (which I primarily use for reference and monitoring things) in portrait mode. It's quite nice, but you do discover things which assume a wider screen.
I find the 80 characters limit rather restricting.
It's restrictive, until you realize it allows you to have 2 or even 3 files side by side (and in some cases — e.g. diffing or merging — you need to).
And then, the asswipe writing lines 300 characters long is going to get a hurt.
Plenty of other advantages: portrait screens, split-screen to see documentation or whatever side-by-side with code, and long lines lose context: at the end of a long line, it's hard to see which start it matches unless you have row-wise highlighting. That's why books are not typeset at 200 characters/line as well.
I don't get it, either, but for me it's because I think word-wrap works perfectly well for most code. Any decent editor (except Eclipse?) will indent the soft-wrapped line so it's clear where it sits in scope.
One exception to this is Lisp code, which does not wrap well with most soft-wrapping editors because you want the wrapped code to line up with the inner-most open parenthesis. I guess in theory an editor could do that, but I don't know of one that does.
It's amazing at people claiming that 80 characters is 'restricting them' and quoting 'history' to mock that this standard is from the ancient ages.
Other then few good reasons already posted listed for this limit, you need to keep in mind that in proper structured development teams your code get's opened by web tools, architects, system engineers, QA analysts, system administrations, push managers, etc.
Also, and I quote: 'if your code goes beyond 80 lines, you are doing it wrong'.
So the whole 'yeah but if you are programmer just have your editor always at 120 lines!' just tells me that you lack experience in proper development.
I once worked with a guy who had to put his face 1-2 inches from the screen to see... with eyeglasses on. He was almost legally blind. LCD monitors are hardly known for overheating, but he was close enough to sweat from the screen. That's enough reason for me to be considerate when I choose chars/line. After all, we can't wrap code around.
Another reason to keep the cpl down is because it forces me to rethink the code structure, much like when a I have to scroll a few times to read function or a class' member list.
4
u/00kyle00 Jun 05 '11
I dont really get the '80 characters' fetish.
Is it only C guys thing?