[Info] PEP 308 accepted - new conditional expressions

  • Thread starter Reinhold Birkenfeld
  • Start date
P

Paul Rubin

Reinhold Birkenfeld said:
For a conditional, syntax must be found, and the tradition of Python
design is not to use punctuation for something that can be solved with
keywords.

Yeah, "if C then A else B" is a ancient tradition stretching from
Algol-60 to OCAML, and who knows what all else in between. I'm not
sure what Guido saw in the "A if C else B" syntax but it's not a big deal.
 
J

John J. Lee

Michele Simionato said:
Guido could have decided two years ago, sparing us the PEP 308 ordalia.
So, I am happy that at the end we will have a conditional operator, but
I am not happy of how the process worked out. It was just an enormous
waste of resources that could have been employed much better :-(

Seems that's what Guido thinks too:


http://mail.python.org/pipermail/python-dev/2005-September/056561.html

| If there's one thing I've learned from the PEP 308 vote, it is that
| votes for language don't work. I prefer some discussion on Python-dev
| after which I pick one.

I think he said at the time that it was an experiment.


John
 
S

Sam

Leif said:
What _isn't_ Perl-ish?

BASIC?



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.7 (GNU/Linux)

iD8DBQBDPqJwx9p3GYHlUOIRAnrgAJ4vgWBuiS8E9vq93mQSuXvJ2OBtAwCeMeR0
CemAKp04FEQ3vlz0LFoY1Go=
=IP0a
-----END PGP SIGNATURE-----
 
R

Ron Adam

Reinhold said:
Ron Adam

Yes, that's the best way to make it readable and understandable.

Reinhold

Now that the syntax is settled, I wonder if further discussion on the
contextual behavior could be done? Or maybe it was already done off
line or in private email?

To me the advantage of a if b else c form is the easy chaining to build
up a sum of conditional parts, where each next part is dependent on the
previous result.

The advantage of the nested form, is it can be used in place of an
if-elif-else structure. But I think the (a if b else c) syntax doesn't
match that behavior very well so I was expecting the default behavior to
be the sequential chaining and not nested evaluation.

But of course, by explicitly placing parentheses, you can do either.
<Shrug>

Cheers,
Ron
 
G

Guest

The lesson for me is to spend much less time on Python discussion and much
more on unfinished projects. So even if I never use the new syntax, I will
have gained something ;-)

QOTW?
 
M

Michael

Rocco said:
That is, what would happen with the following constructs:

A if B else C if D else F
A if B if C else D else F

The correct answer should be the person who wrote it would get told off
for writing code that a person reading would have no idea what the code
was doing (without understanding the precedence).

Whilst it's good to have clear understandable, well defined rules for
these things, that's no excuse for having unreadable code that other
people can't read and understand without having to remember obscure
rules.

Personally, I'd hope that any code-linting tools would flag such expressions
as potentially bad because they're not clear. (Whereas bracketed expressions
instantly help here).

Best Regards,


Michael
 
M

Michael

Paul said:
I'm not
sure what Guido saw in the "A if C else B" syntax but it's not a big deal.

Maybe Guido's done some perl programming on the side? When I've been doing
perl programming I've quite liked the .... if (...); construct, however, on
occasion it's been desirable to have an else there. By having an else there
it means you don't need the ?: syntax and can just have one syntax.

On the flipside, people with different mother tongues often have a different
way of using language. (eg lots of non-native english speakers speaking
better english than those with english as their mother tongue :) And
sometimes that different way can be better ?

Direct translation of german grammatical form for example - resulting in
something looking like yoda speak... Personally I like this form :)

Regards,


Michael.
 
V

Volker Grabsch

Fredrik said:
/... snip comment that the natural order is C, X, Y and that programmers that
care about readable code will probably want to be extremely careful with this
new feature .../

That's also my opinion, but OTOH, Guido's syntax is more close to the syntax
of list comprehensions.


Greets,

Volker
 
A

Antoon Pardon

Op 2005-09-30 said:
This is a MIME GnuPG-signed message. If you see this text, it means that
your E-mail or Usenet software does not support MIME signed messages.
The Internet standard for MIME PGP messages, RFC 2015, was published in 1996.
To open this message correctly you will need to install E-mail or Usenet
software that supports modern Internet standards.

--=_mimegpg-commodore.email-scan.com-32420-1128120829-0002
Content-Type: text/plain; format=flowed; charset="US-ASCII"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit

Reinhold said:
Hi,

after Guido's pronouncement yesterday, in one of the next versions of Python
there will be a conditional expression with the following syntax:

X if C else Y

which is the same as today's

(Y, X)[bool(C)]

What's wrong with "C ? X:Y"?

Aside from ":" being overloaded?

Nothing, but afaiu Guido dislikes it.
 
C

Christophe

Michael a écrit :
Rocco Moretti wrote:




The correct answer should be the person who wrote it would get told off
for writing code that a person reading would have no idea what the code
was doing (without understanding the precedence).

Whilst it's good to have clear understandable, well defined rules for
these things, that's no excuse for having unreadable code that other
people can't read and understand without having to remember obscure
rules.

Personally, I'd hope that any code-linting tools would flag such expressions
as potentially bad because they're not clear. (Whereas bracketed expressions
instantly help here).

Actually, you don't need to know operator precedence here because the
notation isn't ambiguous in those 2 examples. Of course, it takes some
time to understand the thing but it has more to do with the excessive
amount of "logic" in one line than with the syntax.
 
M

Michael

Christophe said:
Michael a écrit :

Actually, you don't need to know operator precedence here because the
notation isn't ambiguous in those 2 examples. Of course, it takes some
time to understand the thing but it has more to do with the excessive
amount of "logic" in one line than with the syntax.

I noted that. However it *does* slow people down which increases the chances
of misconception (which is why I'd be in favour of bracketing these
expressions).


Michael.
 
T

Terry Hancock

That's also my opinion, but OTOH, Guido's syntax is more close to the syntax
of list comprehensions.

GvR's syntax has the advantage of making grammatical sense in English (i.e.
reading it as written pretty much makes sense).
 
R

Robin Becker

As mentioned earlier only a dictator can make such decisions and of course as
with many dictatorships the wrong decision is often made. There's no such thing
as a benevolent dictatorship.
 
E

Eric Nieuwland

Robin said:
As mentioned earlier only a dictator can make such decisions and of
course as
with many dictatorships the wrong decision is often made. There's no
such thing
as a benevolent dictatorship.

Ever cared to check what committees can do to a language ;-)

--eric
 
F

Fredrik Lundh

Terry said:
GvR's syntax has the advantage of making grammatical sense in English (i.e.
reading it as written pretty much makes sense).

as a native Python speaker, I find that argument being remarkably weak. things
I write in Python should make sense in Python, not in some other language.

(besides, we already have way too many languages designed by self-proclaimed
linguists)

</F>
 
R

Robin Becker

Eric said:
Ever cared to check what committees can do to a language ;-)
.....
well there goes democracy :(

-the happy slaves eat and are contented-ly yrs-
Robin Becker
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top