[Python-ideas] PEP 8 update on line length

Chris Angelico rosuav at gmail.com
Wed Feb 20 19:21:53 EST 2019


On Thu, Feb 21, 2019 at 11:09 AM Abe Dillon <abedillon at gmail.com> wrote:
>
> [simon.bordeyne]
>>
>> I find that 100 to 120 characters is ideal as far as line length goes.
>
> Your finding goes against a long history of people attempting to present text in the most readable way possible.
> AFIK, the human fovea hasn't grown much larger in recent years.

You can't see the entire line in focus simultaneously anyway, so the
line length is about how far you can flit your eye left to right, not
the actual fovea itself.

> [simon.bordeyne]
>>
>>  On top of that, it's not uncommon to reach 6, even 7 indentation levels.
>
> It should be pretty uncommon. You might want to re-think your coding style if you're regularly writing code that's so deeply indented.
> A good trick is to use helper functions:
>
> #instead of this
> if condition:
>     ...code
>
> #do this
> if condition:
>     handle_it()

And this is always cited as the "obvious" solution. The trouble is,
unless "handle_it" has a name that tells you EVERYTHING about what it
does, you probably will end up having to go look at its definition -
which means a lot more flicking around. The cost of a long line has to
be balanced against the cost of *avoiding* having a long line.
Splitting a line into consecutive lines has less cost than breaking it
out into a function, *unless* the function truly has its own meaning.

ChrisA


More information about the Python-ideas mailing list