[Python-ideas] Minor tweak to PEP 8?

Guido van Rossum guido at python.org
Thu May 12 00:22:21 CEST 2011


On Wed, May 11, 2011 at 2:44 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> Guido van Rossum wrote:
>>
>> At Google we use the following rule (from
>>
>> http://google-styleguide.googlecode.com/svn/trunk/pyguide.html#Indentation):
>>
>> Yes:  # Aligned with opening delimiter
>>       foo = long_function_name(var_one, var_two,
>>                               var_three, var_four)
>
> I cringe whenever I see that. If people are going to bother lining things up
> other than at 4-space indents, they should at least line them up in a
> visually attractive place. The delimiter should surround the arguments, not
> line up with them:
>
>        foo = long_function_name(var_one, var_two,
>                                 var_three, var_four)
>
> although the effect may be spoiled if you're reading this in a
> non-monospaced font.

I used rich text in gmail and it looks aligned to me. Sorry if it
doesn't for you; as MAL said, follow the link to see how it's supposed
to look.

> This is analogous to the way that professional
> typesetters use handing punctuation:
>
> http://desktoppub.about.com/od/typelayout/ss/hangingquotes.htm
>
>   "Li Europan lingues es membres del sam familie. Lor separat
>    existentie es un myth. Por scientie, musica, sport etc, litot
>    Europa usa li sam vocabular. Li lingues differe solmen in li
>    grammatica, li pronunciation e li plu commun vocabules."
>
> compared to:
>
>    "Li Europan lingues es membres del sam familie. Lor separat
>    existentie es un myth. Por scientie, musica, sport etc, litot
>    Europa usa li sam vocabular. Li lingues differe solmen in li
>    grammatica, li pronunciation e li plu commun vocabules."
>
>
> On the other hand, there's a good argument for not spending the time to
> neatly line up blocks of code (other than at the usual multiples of four
> spaces), whether it is to the delimiter or not.

Emacs automatically does this for me. I spend zero time aligning code.

> It's the same argument
> against doing this:
>
> fee_fi_fo_fum = "something"       # Align the equals
> foo           = "something else"  # and/or the hashes.
>
> When actively changing code lined up like that, you can easily spend more
> time aligning things than programming.
>
> I have a hard time reconciling the advice in PEP 8 against such alignments
> with the current suggestion.

Hardly; that is about spaces *between* tokens. This is about
indentation. The amount of degradation in non-monospace fonts is quite
different. Indentation still looks indented, just not aligned with
[the first character inside] the open parenthesis, whereas internal
spaces look completely jumbled.

IF PEP 8 was still mine I would add this specific rule from the Google
style guide. If people want to bikeshed it to death, go ahead, I will
probably mute the thread.

-- 
--Guido van Rossum (python.org/~guido)



More information about the Python-ideas mailing list