PEP 308: A PEP Writer's Experience - PRO
Roy Smith
roy at panix.com
Sun Feb 9 17:59:27 EST 2003
b_mcerlean at yahoo.com (Brian McErlean) wrote:
> > x > y and x or y
>
> Yes, but this is really a strawman. To be fair, you should argue
> against the "right" way of doing this, which (other than the trivial
> max() for this example) is:
>
> if x > y:
> result = x
> else:
> result = y
I'm probably going to hate myself in the morning, but I'm forced to
admit that, in some ways, the long-winded way (which I've been
advocating) is inferior.
I'm a fan of refactoring (but not a zealot, in the XP-ish "refactor
mercilessly" sense). It's temping to want to factor the "result =" out
of the above and end up with "result = ternary involving x>y, x, and y".
There's both a cognitive advantage (you only have to read and understand
it once) and a coding advantage (if you only type it once, there's no
chance of introducing inconsistancy).
More information about the Python-list
mailing list