PEP308: Yet another syntax proposal

Anna revanna at mn.rr.com
Wed Feb 12 05:36:47 CET 2003


On Mon, 10 Feb 2003 15:52:24 +0000, Raymond Hettinger wrote:

> I suggest:
> 
>     cond  ??  val1  ||  val2
> 
> * Having two characters at each step helps visually segregate the
> components.
> * The ?? and || strongly suggest testing and alternation. * Doesn't
> overload or confuse with existing operators. * No new keywords. *
> In-order presentation.
> * Short and easy to read.
> 
> 
> Using Martin Maney's live code examples, here's what it looks like:
>     i = j>=0 ?? j || n
>     sy = d0.year - (d0.month<7  ??  1  ||  0) add2url = '?' +
>     (params.has_key('add2url')  ??  params['add2url']  ||
> '')
>     tail = (len(events)>1 ??  ' '  ||  '<br>') + tail

Y'know, when I finished my first Python script, I sent it to my tutor and
asked: "So what's the Secret Master Pythonista way of doing this?" His
response is etched in my mind: "Python isn't about taking 10 lines of
perfectly clear code and collapsing it down into 1 line of obscure code.
That's Perl..."

And that keeps coming to mind as I'm reading all these "ternary operator"
syntax proposals... Most of them, to my newbie eyes, are simply confusing,
and seem to fly in the face of what I keep hearing Python is about. Maybe
I'm just being dense, but I haven't seen any that are terribly clear; the
worst ones make me want to pull out a pencil and paper and sit down with
the docs in front of me to try and figure out what the heck it's supposed
to *do*...

...which seems really odd for code that's supposed to be easily readable.

Just my $.03 worth.
Anna
--
Whatever it is, I'm against it. -Groucho Marx




More information about the Python-list mailing list