PEP-308 a "simplicity-first" alternative

Bengt Richter bokr at oz.net
Wed Feb 12 23:05:01 EST 2003


On Wed, 12 Feb 2003 19:05:18 -0800, Erik Max Francis <max at alcyone.com> wrote:

>Bengt Richter wrote:
>
>> This happens to fix the hole in old ternary idiom, but it is _not_
>> introducing a new ternary form or other complex context-dependent
>> stuff.
>> If
>>     (x and [y] or [b])[0]
>> 
>> is understandable, ...
>
>It's "understandable," but it's not very readable, and it's hardly a
>good substitute for a genuine bulitin conditional operator.  The whole
>point of one is to increase readability; this _decreases_ readability
                                          ^^^^--what are you referring to?
>(as does the other form involving and/or and lambdas).
>
Why do you quote the bad old hack and leave out the better alternative
I was proposing, and which was the point? I.e.,
"""
If 
    (x and [y] or [b])[0]

is understandable, why not the much simpler logical-true-wrapper in

    x and {y} or b

?
"""
Are you saying that

    x and {y} or {z}

is not readable, assuming you're familiar with the old idiom?
Newbie-obvious no, but how long would it take you to learn to use it?
Especially since you could just use it, and ignore fine points
about what would happen if a bare y was logically a false value.

Is this really cleaner?

   (if x: y else: z)

This isn't an all-statements-are-expressions language (yet? ;-), after all.
Actually, both could be implemented without interfering, and we could
see how it got used ;-)

Regards,
Bengt Richter




More information about the Python-list mailing list