PEP-308 a "simplicity-first" alternative

Dave Brueck dave at pythonapocrypha.com
Wed Feb 12 01:24:24 CET 2003


On Tue, 11 Feb 2003, holger krekel wrote:

> Every ternary op construct needs time to get used to it, i am afraid.

Some more than others, of course.

> Everything else would be surprising. From there it's only a short
> way to "getting it".  In real life examples (taken from stdlib) like
>
>     run==1 and '' else 's'
>
>     cl and cl.__name__ else ''
>
>     unicode and self.ugettext else self.gettext
>
> i don't think it's "entirely non-obvious" for you anymore?

Well, I've tried to objectively "try out" each proposal so far and,
frankly, this is by far the least readable to me. It's basically the same
old and-or trick, which IMO isn't readable either.

What I like about the other proposals is that, even if you aren't familiar
with them, you have a very good chance of correctly guessing what they are
trying to express.

For me the readability problem with the and-or workaround lies in the fact
that the result of (x and y) is "first false value or the last value". In
and of itself it's sort of magic because it blurs the lines between
straight boolean operations and selecting a value, but it's not too bad.
But do normal (non-Tim) Pythonistas really chain them together that often
(x and y and z) for coming up with anything other than a _boolean_ value?
I doubt it - it just becomes too confusing, especially when you mix
operators (x and y or z).

-Dave





More information about the Python-list mailing list