From: Steve Holden on
Robert Fendt wrote:
> 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.

It exists because people nagged Guido mercilessly until, against his
better judgment, he capitulated.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
See PyCon Talks from Atlanta 2010 http://pycon.blip.tv/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS: http://holdenweb.eventbrite.com/

From: MRAB on
Robert Fendt wrote:
> 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.
>
I think you mean that it's very _un-Pythonic_ (perhaps because it's very
very Pythonesque)! :-)

>> 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.
>

From: Robert Fendt on
And thus spake MRAB <python(a)mrabarnett.plus.com>
Tue, 30 Mar 2010 22:43:04 +0100:

> I think you mean that it's very _un-Pythonic_ (perhaps because it's very
> very Pythonesque)! :-)

Yes. Of course. What was I thinking. ;-)

Regards,
Robert

From: Stephen Hansen on
On 2010-03-30 13:16:00 -0700, Robert Fendt said:
>
> 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.

In Python before list-comprehensions, I might have agreed with you.
Initially, I was quite resistant to list comprehensions as well. They
seemed ugly, and backwards, and why not just write a for loop?

Then I got used to them, and I find they are very elegant when used
properly. Sometimes you can do something ugly with them, but its
actually quite possible to write positively hideous Python even without
any of these new fancy shmancy features.

But, in the post-comprehension world, where one can do:

my_odds = [x for x in range(100) if x % 2 == 1]

Things have changed. I've now grown used to reading expressions like
that which seem a bit backwards, with the value being returned by an
expression is the left-most element. Its not an exact correlation
because they're answering different problems.

But having gotten used to list comprehensions, and actually quite
appreciating their elegance now, I find this reads very well:

is_odd = "odd" if x % 2 == 1 else "even"

In fact, it reads better then any of the other conditional expression
syntaxes people proposed back in the day, and a LOT better then what
was done before:

is_odd = x % 2 == 1 and "odd" or "even"

Even if the above falls a bit more in line with what other languages
usually do order-wise, this isn't other languages.

Now, none of this addresses your original argument of why not just use
a regular if statement.

I dunno, I often used "and/or" for simple expressions or defaults and
found it very convienent and made code more readable then the line and
whitespace inducing true if-statement. And so I'm glad to have
something even more readable and without the bug-prone and/or error.

Why not just use a for loop anytime you use a list comprehension? :)
Same question really applies.

--
--S

.... p.s: change the ".invalid" to ".com" in email address to reply privately.

From: Lawrence D'Oliveiro on
In message <7316f3d2-bcc9-4a1a-8598-
cdd5d41fd74b(a)k17g2000yqb.googlegroups.com>, Joaquin Abian wrote:

> (a==b) and 'YES' or 'NO'
>
> Yes, ugly

Why would you say that's ugly?

By the way, you don't need the parentheses.