On Jun 24, 2019, at 10:27, Dan Sommers <2qdxy4rzwzuui...@potatochowder.com> 
wrote:
> 
> On 6/24/19 12:32 PM, James Lu wrote:
> 
> > I think
> >
> > print("Remember to wear sunscreen!") if hot_outside unless 
> > Weather.is_raining()
> >
> > Is more readable than
> >
> > if hot_outside and not Weather.is_raining(): print("Remember to wear 
> > sunscreen!")
> 
> I disagree, but that's bound to happen in a discussion like this.

I also disagree. And I think there’s a principled reason for it.

In a language like Perl, where there’s little consistency in syntax and flow 
control is scattered all over the place, this would be great. You can write the 
code in the same order as the sentence you’re thinking in your native language. 
In fact, Perl added postfix conditionals back in version 4 or so, and everyone 
loved it.

But in Python, flow control is restricted to compound statements, which all 
have the same form: a colon and an indebted block. This makes Python a lot 
easier to read.

While it’s _possible_ to escape from an expression by intentionally calling a 
function that raises, or to bury side-effect-only function calls deep in an 
expression, it’s considered bad style, and only done in rare, exceptional 
cases. What’s being proposed here is to add a new way to do that. So, either 
it’s deliberately encouraging bad style, or it’s something that would be so 
rarely used that it’s not worth it. 

What about comprehensions? They _do_ have flow control within an expression, 
and even spell it with a postfix condition. But comprehensions are a highly 
restricted mini-language, where the only flow control possible is skipping, and 
the syntax encourages you to keep them short and simple. So they turn out to be 
worth it.

Which is exactly why the more restricted version of the proposal—only allowing 
“pass” (or however  it’s spelled) inside displays (and “tuple displays”) and 
argument lists—might be worth it, even if the fully general one isn’t.

That being said, I still haven’t seen an example of a function call or list 
display that actually looks compelling. I think if anyone wants to convince 
everyone that some form of this proposal is worthwhile, that’s the first thing 
they need to provide.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/BGFUVTYMDHI27QAQ6XA6ZK677JOD44HV/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to