Monday, February 23, 2015

In Defense of 80-Character Lines

Given the proliferation of big laptop screens and the current rise of 4K monitors, it's hard to imagine why the old programming practice of "80 characters per line" (80 CPL) would still apply.  We have all the screen real estate we need, right, so why restrict ourselves?  As it turns out, I'm still a big proponent of 80 CPL limits for software projects written in high-level programming languages.

HISTORY
Although most typewriters had standardized on 72 CPL by mid century, IBM's well-known punch card system standardized the 80-character limit. This limit continued in the terminal interfaces of the next generation.  Today, we don't have any such system-enforced limits, but many software development teams implement them anyway as a code style guideline.

SIZE STILL MATTERS
Even with today's huge screens, 80 characters per line is still helpful.  Many developers use IDEs or tools like Vim to display multiple source code files side-by-side on screen.

Vim session split vertically with 80 CPL source code
80 CPL is great because it lets developers view two source files side-by-side on most laptops screens with a reasonable font size (10-16 pt. range).

KEEPING IT TERSE
More importantly, though, having an 80-character limit forces developers to constrain the amount of logic in one line of code.  Do you really need that ten-method chained ActiveRecord query on a single line?  Hitting the 80 character limit is a great indication that you should refactor your code and break things out so they're more readable.

Does your software team enforce a characters-per-line limit?

No comments: