Line Limits

There are those who feel arbitrary line limits are a bothersome, vestigial construct of the bygone age of punch card programming. Why must we continue to constrain ourselves to archaic requirements imposed upon us by the technological limits of days gone by?

I shall tell you why, for I am not one of those people. Here are the reasons why some of us continue striving to keep our lines under 80 characters:

  1. 80 characters is the natural length that the human eye can read without scanning. Once you pass that length, you have to scan, and the lines become progressively harder to grok.
  2. Long lines in a programming file are a code smell that you may be trying to do too much or be too clever on that line. Almost every time you can clean it up and make it easier to understand by extracting things to an explaining variable or using a named function to handle it. Or it could be a code smell that you are nesting too many if statements together because you’re running out of room.
  3. Long lines in a view template likely means that you’re not nesting attributes or tags as much as you could be. Or it could be a code smell that you’re nesting too many tags inside each other and you should extract pieces into a partial / directive / etc.
  4. The advantage of setting an arbitrary line length means that your code will always look good when you use the features of a good editor like splits to view multiple files at once. This is because it forces you to wrap the lines at a human-readable point. If you simply set your editor to wrap lines for you and you try to use splits, it will make the code far more difficult to read because everything just jumbles together because the computer isn’t smart enough to wrap the lines at a logical place in the code.
  5. If your code stops at 80 characters, its a lot easier to copy / paste a snippet onto a blog post or chat client.
  6. If you contribute to Open Source projects, many of them enforce an 80 character line length.

So there you have it. If you think that fighting long lines is a noble cause, you can add a subtle vertical bar or a character counter to your code editor of choice. For example, I use MacVim with a dark color theme, so I added this to my ~/.vim/.gvimrc:

" Show the Color Column and set it to 80 characters.
set colorcolumn=80
hi ColorColumn ctermbg=Black guibg=#111111


tldr; I think that line lengths are still valid because they help you write better code.