Testing Coding with an 80 Character / Line Limit

First, a little history for any not in the know. Computer monitors didn’t used
to provide graphical interfaces for users. Users would set down and start a
terminal session. These sessions would be text-based and the monitor resolutions didn’t allow for lines hundreds of characters long.

Old Terminal Monitor

If you wanted to write some code and have it displayed on a line without
requiring scrolling, then your code lines had a limit of 80 characters.

There has been some discussion of this recently, because Python’s recommending coding standards in PEP-8 suggest a character limit of 80 characters per line. I know I’ve seen multiple articles on this point hit the front page of Hacker News. Some people feel that this is crazy since today’s monitors are larger and resolutions greater. There have been suggestions that a better limits would be 100, 120, or 150 characters. Is that true?

Thinking about this, I realized that I didn’t have the experience to form a
solid opinion. I had never taken line length into consideration when writing
code. Maybe this is the only information I should need to form an opinion, but
I decided instead to place guidelines in Visual Studio and Notepad++ at 80
characters to try to keep myself within the limits.

How did I react to this change?

At first I fought it. This should be expected. Why should I force myself to
80 character lines? I can go longer. It’s fine. But, this would have been a bad
experiment. In forcing myself, I eventually became used to creating lines that
were 80 characters max.

My code thanked me for it. All of a sudden there were no errant lines that
stretched across the screen while other lines were short. This created a visual
style that was actually easier to follow with my eyes when reviewing code.

My design also thanked me for it. Suddenly nesting became a serious issue — one level of nesting cut 4 characters out of any following code. I’ve got code
that’s nested 3 levels deep? Now those lines are limited to 68 characters. This
caused me to start creating smaller methods with more descriptive names and no side effects. That’s definitely a good thing. Nesting went down. Code became
more readable.

What was my favourite result?

During code review, people told me that the code read great. They didn’t
notice at all that the lines were 80 characters or less. But when I later told
the same people that I was limiting my line length, they said the idea was silly
and could force areas of poor readability.

These comments were from the same people who had previously read this very same code and found the style praiseworthy. To me, that’s a success.

The guidelines aren’t going anywhere anytime soon.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s