FW: [Python-Dev] conditional expressions?

Steve Holden sholden at holdenweb.com
Tue Oct 16 13:29:09 EDT 2001


"Paul Boddie" <paul at boddie.net> wrote ...
> Anthony Baxter <anthony at interlink.com.au> wrote >...
> > Ok, so we're getting yet another ugly hack added to the language.
> > Could the normal process of writing up a PEP be followed, so that
> > those people in the community who are uncomfortable about it can
> > at least see the justification for this?
>
> Indeed, it would be interesting to see the justification for
> conditional expressions, apart from the fact that "it can be done", of
> course.
>
It seems to me that increasing the number of contexts in which the keyword
"if" is meaningful could represent a real learning setback to new Python
users.

> Given time, we all accept change. I accept now that the division
> reform was probably necessary due, in part, to some bizarre behaviour

[ ... bizarre divide behavior described ...]
>
> Still, some people have already openly wondered about the usefulness
> of implementing countless "ugly hacks" when more interesting or
> "necessary" challenges exist, particularly in the area of searchable
> module catalogue services, to name one recent "hot topic"...
>
Certainly, from an implemetor's point of view, the justifications are
different from the users'. However, I feel we can have faith that Guido will
continue to see the "big picture" as far as language development is
concerned.

Certainly this seems far too recent a development to include in 2.2 (even if
it can easily be done): more time is required for the implications to be
fully appreciated by those of us who don't poke around in the system's
internals every day.

I particularly shudder for the newbie who must read something like the
following (untested code warning: I'm not building an interpreter that can
handle this stuff, because I'm hoping it will disappear <0.75 wink>):

l = if a then [i for i in l1 if i % 2] else [i for i in l2 if not i % 2]

Of course, this might also be cast as:

l = [i for i in (if a then l1 else l2) if (if a then i % 2 else not i % 2)]

This may not be the best way to implement such an expression, but if it can
be done then someone will do it. It contrasts quite badly with:

if a:
    l = [i for i in l1 if i % 2]
else:
    l = [i for i in l2 if not i % 2]

"ick" doesn't even beging to describe it. Save the newbies !!!

if-i-had-a-vote-it-would-be-against-ly y'rs  - steve
--
http://www.holdenweb.com/








More information about the Python-list mailing list