Proposed PEP for a Conditional Expression
johnroth at ameritech.net
Mon Sep 10 08:29:21 CEST 2001
"Michael Chermside" <mcherm at destiny.com> wrote in message
news:mailman.1000046772.19777.python-list at python.org...
> Included in this email is a PEP which I am putting together dealing with
> the idea of introducing a conditional expression into Python. I would
> welcome any discussion, suggestions, and/or help, sent either to this
> newsgroup under this topic, or emailed to me at <python at mcherm.com>.
Very nice summary of the discussion. In looking it over, I finally think
I understand why workaround 3 works. Ugly as it is, it fills what need I
have for this construct.
Part of the ugliness is that it's built on the "and" and "or" blivit. I'll
you that it's a useful blivit, but it's still one of the points that tends
astonish the novice, and leads to arcane errors when some instance
you thought was true turns out to be false because the class implements
a __len__ function.
I have mixed feelings on the "lends itself to obfuscation" issue. Python is
probably the hardest language I know of to obfuscate because of the
forced indentation. Not that it's impossible, it just takes more work. On
the other hand, when a method goes over one screen, it's a maintainability
I also have mixed feelings on the "keep it simple" issue. Simplicity is one
of those issues with multiple valid viewpoints. For me, simplicity is an
absence of special cases. In another post, someone asked that the
.count and .index methods be made available for tuples. For me, this
is simpler than not having them: the argument that a tuple is immutable
and a list is mutable simply makes no sense - it has nothing whatever
to do with the functionality of the method, and is simply one more
arbitrary rule to keep in mind.
None of the proposed syntaxes grab me; some are worse than others,
but none of them stand out and say "right!" If pressed for a preference,
I'd go with ?:, simply because it's familiar from C.
More information about the Python-list