For review: PEP 308 - If-then-else expression

Paul Rubin phr-n2003b at NOSPAMnightsong.com
Sat Feb 8 15:11:28 EST 2003


Dale Strickland-Clark <dale at riverhall.NOTHANKS.co.uk> writes:
> As far as I can see, there are still only two serious contenders:
> 
> a) special characters: cond ? exp1 : exp2
> 
> b) textual:            cond if exp1 else exp2
> 
> The others suggestions offered in response are ethier pointless (they
> offer nothing not already in the proposal) or have missed the point.
> 
> a) has been criticised for being C-like and b) for being Perl like.

I think in PEP 308, a) was criticized because it used a new
punctuation character (?) and overloaded colon.  The overloading
of : can be solved by combining the two contenders:

    cond ? exp1 else exp2

I'm not saying that's a good idea, but only that it's possible.

I'm certainly opposed to the idea that if C did something one way,
Python MUST do it a different way.

I do think that the concepts of Pythonic, C-ish, and Perl-ish actually
mean something and it's fine to react to something Perl-ish as seeming
out-of-place in Python.  I find that less true for C-ish-ness since
C's philosophy is closer to that of Python.  Perl's big experiment is
in allowing a range of syntatic transformations on statements similar
to what English allows.  Most other programming languages don't try to
do that and the results haven't been (IMO) so hot for Perl.  On the
other hand, some non-syntactic Perl features (like string
interpolation) work very well and I'd be happy to see Python import
them.

Btw, just the other night I discovered that Python has a feature that
I first saw in C: you can enter a list or tuple with an extra comma at
the end (like [2,3,5,] , and the extra comma is ignored.  I think that
feature was added to C for the sake of easing the job of automatically
emitting tables for use in C programs, i.e. to simplify Yacc.




More information about the Python-list mailing list