A desperate lunge for on-topic-ness

Roy Smith roy at panix.com
Sat Oct 20 16:37:23 EDT 2012


In article <5081d0c3$0$30003$c3e8da3$5496439d at news.astraweb.com>,
 Steven D'Aprano <steve+comp.lang.python at pearwood.info> wrote:

> Some code might be more conveniently written as a single long line. But I 
> would argue that nearly never is code more easily *read* as a single long 
> line, and since code is read much more than it is written, it is more 
> important to optimise for reading, not writing.

Like many people here, I don't worry much about the 80 column limit.  I 
make my lines of code as long as they have to be, and no longer.  If 
there's some obvious and easy way to fold the statement onto multiple 
lines, I'll do it.  If not, I won't.

This tends to result in lines that are less than 80 characters, but if 
not, I don't worry about it (assuming I'm even aware of it).

I just did a little experiment.  I took about 20 KLOC of python that was 
largely written by me and make a histogram of the line lengths 
(http://www.panix.com/~roy/length.pdf).  Just by eye, I'd say "most are 
less than 80, almost all are less than 100".  I'd guess the average of 
all non-empty lines is about 45 or so.  The longest line is 273 
characters:

             sys.stderr.write("Error: Can't find the file 'settings.py' 
in the directory containing %r.\nYou'll have to run django-profile.py, 
passing it your settings module.\n(If the file settings.py does indeed 
exist, it's causing an ImportError somehow.)\n" % __file__)

Would that have been better rewritten broken up into several shorter 
lines?  Absolutely.  Such is life.

PS: I didn't write that line :-)



More information about the Python-list mailing list