Maximum line length restriction

The 79 char limit is about readability, not screen size. There is a
reason that almost every book, magazine and newspaper on the planet has
converged to something around 55-65 characters per line. It is the
biology of vision, not the size of the paper.

It doesn’t matter how wide your screen is, human vision is still the
same as it was 40 years ago, or 400 years ago. 55-65 characters for
prose text is close to optimum. Doubling that to 110 or 130 characters
is less readable, causing more eyestrain, no matter how enormous your
screen is.

Programming code is not quite the same as reading prose text arranged in
paragraphs, so we can extend that line width a little bit: 79 chars is
okay, since most lines won’t come even close to that limit. It’s even
okay to occasionally go over the limit by a few extra characters. But if
you are regularly hitting 90 or 100 columns, then your code probably has
problems:

  • your code may be too deeply indented;
  • you may be squeezing too many operations into a single line;
  • (trying to do too much in one line – Python is not Perl!);
  • that includes violating the Law of Demeter;
  • or you may be using unnecessarily verbose variable and function names.

It is difficult to come up with code that cannot be improved and made
more readable by keeping to 79 characters. But don’t be a zealot though:
if you occasionally hit 81 or 82 characters, who cares?

Possibly the main exception I can think of is when you have a big table
of data in a list or dict formatted right there in the source code,
where keeping the data neatly formatted is more important than squeezing
it into 79 columns.

Another exception is, ironically, exceptions frequently exceed 79
columns, including the indent, “raise SomeException(long message…)”.

But for general code, if you are frequently exceeding 79 columns by a
lot, that is a strong sign that your code could probably be improved by
refactoring.

And if you disagree? Okay, you disagree. For your private software
projects, you can use any line width you want.

There are other reasons why many people prefer to stick with a line
width of 79 columns. That lets them put three files side-by-side, or two
files and the interpreter, without needing horizontal scroll.

8 Likes