PEP 8 : Maximum line Length :

Ben Finney ben at benfinney.id.au
Tue May 13 08:26:40 EDT 2014


Roy Smith <roy at panix.com> writes:

> >    p = Subprocess.Popen(shlex.split(cmd),
> >                         stdout=subprocess.PIPE,
> >                         stderr=subprocess.PIPE)

That is PEP 8 conformant, but I find it hurts maintainability: it is far
too much indentation. Horizontal space is costly, because so much
indentation severely limits the length of names etc. that you can use on
the continuation lines.

Worse, it is also needlessly tying all the continuation lines to the
length of the text before the open paren. What if ‘p’ changes to some
other name?

With the style I've advocated::

    p = Subprocess.Popen(
            shlex.split(cmd),
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)

Changing the name on the first line doesn't entail changing any other
line::

    proc = Subprocess.Popen(
            shlex.split(cmd),
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)

    special_process_map[this_process] = Subprocess.Popen(
            shlex.split(cmd),
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)

Whereas with your suggestion, every line would need to change simply
because the first one did::


    special_process_map[this_process] = Subprocess.Popen(shlex.split(cmd),
                                                         stdout=subprocess.PIPE,
                                                         stderr=subprocess.PIPE)

Yes, that's contrived. But I prefer to use a style that doesn't need to
deal with the issue of when the indentation has gone too far for a
single statement.

It's for both those reasons that I recommend avoiding the “align with
open bracket” style, and instead use a standard eight-column indentation
for continuation lines.

-- 
 \          “One bad programmer can easily create two new jobs a year. |
  `\      Hiring more bad programmers will just increase our perceived |
_o__)                     need for them.” —David Lorge Parnas, 1999-03 |
Ben Finney




More information about the Python-list mailing list