From: Robert Kern on
On 2010-03-30 12:11 PM, Steven D'Aprano wrote:
> On Tue, 30 Mar 2010 10:08:31 -0700, John Nagle wrote:
>
>>> Yes, Python has ternary operator-like syntax: return ('Yes' if a==b
>>> else 'No')
>>>
>>> Note that this requires a recent version of Python.
>>
>> Who let the dogs in? That's awful syntax.
>
> I used to think so to, but now I like it. It matches common English
> syntax like:
>
> "I'm going to the movies tonight, if I leave the office early, otherwise
> I'll stay home and nitpick on Usenet."

I would suggest that this is much more common and less awkward English usage:
"If I leave the office early, I'm going to the movies tonight; otherwise, I'll
stay home and nitpick on Usenet."

I don't have a problem with the current syntax, and while its English analogue
is grammatical, I don't think you can rightly call it idiomatic.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

From: Robert Fendt on
And thus spake Steve Holden <steve(a)holdenweb.com>
Tue, 30 Mar 2010 13:56:04 -0400:

> >> Yes, Python has ternary operator-like syntax:
> >> return ('Yes' if a==b else 'No')
> >>
> >> Note that this requires a recent version of Python.
> >
> > Who let the dogs in? That's awful syntax.
>
> Yes, that's deliberately awful syntax. Guido designed it that way to
> ensure that people didn't aver-use it, thereby reducing the readability
> of Python applications. Speaking purely personally I hardly ever use it,
> but don't dislike it.

In fact, the syntax just shouts 'do [...] unless' to me. And
that's so strong a Perl-ism I cannot quite express how ugly I
actually find it...

Regards,
Robert

From: John Bokma on
Robert Fendt <no.spam(a)local.local> writes:

> In fact, the syntax just shouts 'do [...] unless' to me. And
> that's so strong a Perl-ism I cannot quite express how ugly I
> actually find it...

And

a == b and 'Yes' or 'No'

isn't a Perl-ism?

Sheesh, this group would be so much nicer without the constant dragging
in of Perl to make a point. On top of that, do { } unless blocks are
not idomatic in Perl. Perl Best Practices even clearly states to *never*
use unless.

--
John Bokma j3b

Hacking & Hiking in Mexico - http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
From: Pierre Quentel on
On 30 mar, 21:19, John Bokma <j...(a)castleamber.com> wrote:
> Robert Fendt <no.s...(a)local.local> writes:
> > In fact, the syntax just shouts 'do [...] unless' to me. And
> > that's so strong a Perl-ism I cannot quite express how ugly I
> > actually find it...
>
> And
>
>  a == b and 'Yes' or 'No'
>
> isn't a Perl-ism?
>
> Sheesh, this group would be so much nicer without the constant dragging
> in of Perl to make a point. On top of that, do {  } unless blocks are
> not idomatic in Perl. Perl Best Practices even clearly states to *never*
> use unless.
>
> --
> John Bokma                                                               j3b
>
> Hacking & Hiking in Mexico -  http://johnbokma.com/http://castleamber.com/- Perl & Python Development

I'm surprised nobody proposed a solution with itertools ;-)

- Pierre
From: Robert Fendt on
And thus spake John Bokma <john(a)castleamber.com>
Tue, 30 Mar 2010 13:19:19 -0600:

> And
>
> a == b and 'Yes' or 'No'
>
> isn't a Perl-ism?

I never said that this would be better. I don't even get the
point of what the advantage is supposed to be of inverting the
order of the return statement and the conditional check what
should actually _be_ returned. What's wrong with just writing

if a==b:
return 'Yes'
else:
return 'No'

apart from it being a few more line breaks and an additional
return statement? The inverted form is not more readable per
se (in fact, quite the opposite), and I would even suggest to
minimise its use even in languages like C++ and Java. The Python
syntax is even worse since it not only inverts the order of
return statement and conditional check, but it also puts the
conditional between the two results.

I find such a convoluted construct especially ugly in a language
which I previously regarded as having a rather striking beauty
of syntactical simplicity. The construct is superfluous,
illogical, unelegant, and thus very un-pythonesque, IMHO. But of
course that's just my $0.02.

> Sheesh, this group would be so much nicer without the constant dragging
> in of Perl to make a point. On top of that, do { } unless blocks are
> not idomatic in Perl. Perl Best Practices even clearly states to *never*
> use unless.

Sorry, but you have just underlined my point, in fact. If it's
discouraged by experts, then of course the question must be
valid why such a feature even exists (okay, apart from 'it
seemed like a good idea at the time'). And more importantly (and
more on-topic here), why we have to have an analogon in Python.

Regards,
Robert