PEP 8 : Maximum line Length :

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu May 15 22:25:44 EDT 2014


On Thu, 15 May 2014 06:58:53 -0700, Rustom Mody wrote:

> As far as I can see the votaries of the mystical 79 have yet to explain
> how/where it appeared from

You're either trolling, or haven't been reading this thread in any 
detail. That's already been explained, repeatedly both in this thread and 
many times over the years: 79 is one less than 80, which is the standard 
width of many editors, which in turn comes from old dedicated terminals.

Given your use of deliberately provocative terms like "votaries" and 
"mystical", I would say you're trolling.

On the chance that you are asking an honest question, there's nothing 
"mystical" or magical about the number 79, or 80. 80 is a de facto 
standard. Had history turned out a bit different, that standard might 
have been 90 characters, or 70. Less likely (because people 
psychologically have a preference for multiples of ten over "random" 
numbers) it could have been 65, or 93, or any number somewhere in that 
range of 60 to 100 or thereabouts.

But once a standard is established, even an arbitrary standard like 80 
columns -- but not *entirely* arbitrary -- there is value in sticking to 
it *just because it is the standard*. There's nothing "mystical" about 
driving on the left hand side of the road (on the right hand side for 
Americans), but whatever choice everyone else has made, you really ought 
to do the same. Following the same standard simply makes interoperability 
easier and reduces friction.

But as I said, 80 isn't *entirely* arbitrary. 8 characters would be too 
few; 800 would be too many. Approximately 60 to 100 characters or 
thereabouts is the "Goldilocks" zone of "not too few, not too many" for 
most texts.

Think of it this way: every time the reader has to scroll horizontally, 
consider that as a page fault (it's an order of magnitude slower than 
scanning with the eyes). Every time a single logical expression has to be 
split over two lines, that's also a page fault. Every time you read a 
line of complicated code that does too much, that's also a page fault. We 
want to minimize the number of page faults.

A limit of 60 characters would minimize the number of horizontal 
scrolling page faults (hardly anyone has their editor to display fewer 
than 60 characters!), but increase the number of expression-splitting 
page faults. A limit of 120 characters would reduce the number of 
expression-splitting page faults, but increase the number of horizontal-
scrolling faults, and encourage people to write long lines of complicated 
code that does too much. Somewhere in between is a range that minimizes 
the number of page faults, hence maximizes readability.

There's unlikely to be "One True Best Answer" to maximize readability at 
N characters, because maximum readability is dependent on the context. 
One can only hope to get close to maximum readability for a range of 
typical text, including code. That's likely to be around 80 characters, 
which fits nicely with the historical standard. Reducing that to 80-1=79 
means you're protected from "off-by-one" errors in either your counting 
or your editor.



-- 
Steven D'Aprano
http://import-that.dreamwidth.org/



More information about the Python-list mailing list