python styles: why Use spaces around arithmetic operators?

Stephen Hansen me+list/python at ixokai.io
Mon Jul 26 22:35:24 EDT 2010


On 7/26/10 3:20 PM, Peng Yu wrote:
> This webpage http://www.python.org/dev/peps/pep-0008/ recommends the
> following. It looks to me that both styles are fine. Could anybody let
> me know what the rationale is behind this recommendation?

PEP8 is a style guide. Parts of style guides are rational judgements and
decisions based on experience and can certainly be "explained" or
justified, but parts are just... personal taste. Style is part rational
thought and part intuition, and in the latter -- people will disagree
quite a bit. There's no right or wrong there. There isn't always a
rationale.

Guido finds "x=a+1" less readable then "x = a + 1". Originally he wrote
this down with other anecdotal little tidbits up into an eassy and
posted it on the python.org website. Eventually, others decided that his
intuitive sense of style actually tended to be rather spot on for them
too (why wouldn't it, since that same sense of style brought Python into
existence and most of us quite like it), and so that guide and some
others were codified into PEP8, and tweaked from time to time.

PEP8 is only a "rule" for the stdlib, and only for new code in the
stdlib at that -- and its only really a rule to encourage consistency
and maintainability, not because its objectively The Right Way To Code.

Personally, while I agree with much of it, I disagree in several points
and ignore PEP8 whenever it suits me (most notably on line length rules,
and for a long time on methodNamingSchemes, but lately I've found I'm
coming_around).

-- 

   Stephen Hansen
   ... Also: Ixokai
   ... Mail: me+list/python (AT) ixokai (DOT) io
   ... Blog: http://meh.ixokai.io/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 487 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20100726/d3c4a76e/attachment.sig>


More information about the Python-list mailing list