[Python-ideas] Evolution of Style Guides

Andrew Barnert abarnert at yahoo.com
Wed Mar 18 08:18:02 CET 2015


On Mar 17, 2015, at 11:33 PM, Ian Lee <ianlee1521 at gmail.com> wrote:
> 
> 
> * There are a number of checks that are disabled in pep8 by default, due to their being somewhat controversial for many users [5] which you can read about what each of them are for in the docs [6] if you're interested.

I don't know that the rules themselves are necessarily controversial, so much as the way the checks are implemented.

I enabled E226 to see what it does (just because it sounded like the easiest one to test without reading further).

It flags the "Yes" examples from the PEP ("c = (a+b) * (a-b)")
as an error, and passes the corresponding "No" examples ("c = (a + b) * (a - b)"). No wonder it's controversial.

What's going on? The rule it enforces is "always put whitespace around arithmetic operators", but the rule in the PEP is "If operators with different priorities are used, consider adding whitespace around the operators with the lowest priority(ies)."

But how exactly can an automated checker "consider" doing something? Clearly always doing it is not what's intended. Even besides the examples, in a document that starts off by telling you it's only a guideline and should not be followed slavishly or rigidly, any part that goes out of its way to say "consider" and follow with "use your own judgment" must have a reason to do so.

So, your judgment can tell you that the No example has too much whitespace. But the pep8 code can't.* And this is, presumably, why the E226 code has no problem with it, which in turn is presumably why users have a problem with the E226 code.

So, I don't think the fact that some of the checks are disabled by default necessarily means there's any dissonance between PEP8 and the Python community, it just means there are things in PEP8 that, though worth following, are hard to codify as rigidly checkable rules.


* Maybe "can't" is a bit strong. But consider: Would your judgment be the same if the variables had longer names? If this were one line of a complicated multi-line expression? Even if you knew the rules that provided the answers to those questions, would you want to code them and turn pep8 into a massive 80s-style expert system?



More information about the Python-ideas mailing list