[Python-Dev] (no subject) (original) (raw)

Michael Chermside mcherm at mcherm.com
Mon Mar 6 23:12:06 CET 2006


Jim Jewet writes:

I can't imagine [a conditional] expression small enough that [requiring] parentheses really hurt.

var = t if c else f var = (t if c else f)

This is a good example. I'm now +1 on adding this to PEP 8. I'm +0 on adding it to the grammer... in the long run it's unlikely to make any difference.

Steve Holden writes:

Contrast with the bleeding obvious:

level = 0 if "absoluteimport" in self.futures: level = -1

Comparing this to the alternative:

level = (0 if ("absolute_import" in self.futures) else -1)

In the latter, level clearly takes on values of 0 or -1. In the former, level has a default value of 0, which is followed by what appears to be some branching logic.

or even, if a certain obscurity is desirable:

level = - ("absoluteimport" in self.futures)

The only USE I have ever seen for code obscurity was in writing certain vote-counting software where the true behavior needed to remain obscure even in the face of source code publication.[1]

-- Michael Chermside

[1] http://graphics.stanford.edu/~danielrh/vote/scores.html



More information about the Python-Dev mailing list