[Python-ideas] Minor tweak to PEP 8?
Steven D'Aprano
steve at pearwood.info
Wed May 11 23:44:44 CEST 2011
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. 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. 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.
--
Steven
More information about the Python-ideas
mailing list