PEP8 79 char max

Steven D'Aprano steve+comp.lang.python at pearwood.info
Mon Jul 29 17:34:44 EDT 2013


On Mon, 29 Jul 2013 15:18:59 -0500, Ed Leafe wrote:

> On Jul 29, 2013, at 3:08 PM, Joel Goldstick <joel.goldstick at gmail.com>
> wrote:
>> Not performance, but human readability
> 
> 	IMO, this isn't always the case. There are many lines of code 
that are
> 	broken up to meet the 79 character limit, and as a result become 
much
> 	less readable.

Speaking of readability, what's with the indentation of your post? The 
leading tab plays havoc with my newsreader's word-wrapping.

Breaking lines to fit in 79 characters should almost always be perfectly 
readable, if you break it at natural code units rather than at random 
places. E.g. I have a code snippet that looks like this:

[....whatever...]
else:
    completer = completer.Completer(
                    bindings=(r'"\C-xo": overwrite-mode',
                              r'"\C-xd": dump-functions',
                              )
                            )

I'm not entirely happy with the placement of the closing brackets, but by 
breaking the line at the arguments to Completer, and then putting one 
binding per line, I think it is perfectly readable. And much more 
readable than (say) this:


else:
    completer = completer.Completer(bindings=
        (r'"\C-xo": overwrite-mode', r'"\C-xd": dump-functions',))


As far as I can tell, that's pretty much the longest line I have in my 
personal code base, possibly excepting unit tests with long lists of 
data. I simply don't write deeply nested classes and functions unless I 
absolutely need to.


-- 
Steven



More information about the Python-list mailing list