In defence of 80-char lines

Mitya Sirenef msirenef at lightbird.net
Wed Apr 3 22:40:51 EDT 2013


On 04/03/2013 09:59 PM, Andrew Berg wrote:
> While I agree that not having a  line take up hundreds of characters is a
 > good thing, 80 is really arbitrary in 2013 and having any self-imposed
 > hard limit is silly. When you put a single 4- or 5-character word on a
 > new line because you don't want to go over 80 (or 120 or whatever), the
 > code is /less/ readable. A better guideline is to make new lines as
 > necessary to make things more readable rather than blindly stick to some
 > hard limit and say it's more readable just because.
 >
 > Also, IMO, 80 is far too limiting and I find 120-130 much better. Then
 > again, I like small font sizes and avoid lower resolution screens like
 > the plague.


I have to agree. To some degree, it's a matter of taste: for me, 80c
limit looks ugly to the extreme, at least in Django; but 140+ looks even
uglier, and the longer line is, the uglier it looks. The optimal size
for Django code is a 105 char soft limit -- by soft limit I mean that
under 105 it's always one line, 105-110 I decide on a case-by-case basis
and over 110 is always split.

So my preference is: 105 > 120-130 > 140 > 80 > 140+

The trade-off is that on one hand, the code is more readable when a
single line is a single "operation", from a cognitive standpoint, when
you're thinking about the logic of the function as a whole, or a subset
of a function if it's too long (which it shouldn't be, right?) On the
other hand, even if your monitor is wide, you probably still want to fit
in the browser window and the terminal window, and as the blog author
rightly notes, really long lines do get harder to read.

Again, I mostly work with Django and I suspect if I worked in regular
Python I would possibly gravitate towards 95-100 limit.

I find the blog author's point about fitting more text nonsensical: you
can obviously fit more text PER LINE if lines are longer! And you can
quite easily fit two 120-130 wide gvim screens on a modern monitor with
room to spare.

I'm sure eyesight acuity also figures into this: I prefer to work
without glasses -- otherwise my eyes get tired after a couple of hours;
but this means I can't see code on my second monitor. If I could, I
might have preferred having browser and terminal on one monitor and Gvim
with slightly longer width limits than I use now.

  -m


-- 
Lark's Tongue Guide to Python: http://lightbird.net/larks/

The Bible is literature, not dogma.  George Santayana




More information about the Python-list mailing list