Guido sees the light: PEP 8 updated

Chris Angelico rosuav at gmail.com
Tue Apr 19 09:41:06 EDT 2016


On Tue, Apr 19, 2016 at 11:31 PM, Tim Chase
<python.list at tim.thechases.com> wrote:
> Likewise, I detest aligning comments and almost always prefer to put
> them in a neighboring line if there's continuation:
>
>     foo = bar * 3 + 2 # we have 3 bars
>                       # plus one for margin on either side
>
> changing the length of the code portion (say, s/bar/inner_width/) will
> require re-indenting (and possibly re-flowing) the comments.
>
> It's even worse if the comment flows to an unrelated line
>
>     foo = bar * 3 + 2    # we have 3 bars
>     result = apply(bar)  # plus one for margin on either side
>
> Now, if either line of *code* changes, it requires rejiggering the
> comment indentation.
>
> If the comment gets moved above, it's no longer an issue:
>
>     # we have 3 bars plus one for margin on either side
>     foo = bar * 3 + 2
>     result = apply(bar)

Oh, absolutely! If the right-hand comment can't fit in the
right-hand-side, it needs to move above the code. The only time I'll
"wrap" that kind of comment is when it actually applies to both lines
of code:

width = bar * 3 + 2 # we have 3x2 bars, plus one...
height = bar * 2 + 2 # ... pixel of margin on all sides

ChrisA



More information about the Python-list mailing list