Hello,

On Wed, 22 Jul 2020 20:00:29 +1000
Steven D'Aprano <st...@pearwood.info> wrote:

[]

> > >     py> for x in [1,2]:    
> > >     ...     print("inside loop")
> > >     ... else:
> > >     ...     print("elif never looped")
> > >     ... 
> > >     inside loop
> > >     inside loop
> > >     elif never looped
> > > 
> > > 
> > > This is why I have long-argued that the keyword here should be
> > > *then* not else. The semantics are that the loop executes, *then*
> > > the following "else" block executes,   
> > 
> > But no, loop executes, *or else* the following "else" block
> > executes ;-). That's the logic of founding fathers. After one
> > grasped that logic, one comes to appreciate a weird beauty of it.
> > The verdict remains the same though: "Do Not Use".  
> 
> I am confused. I don't understand your comment.
> 
> Your "But no" suggests to me that you are disagreeing with me. Your 
> comment "loop executes *or else* ..." suggests that you are denying
> the evidence of the code, and defending the idea that either the loop
> runs, or the else clause runs, but not both.
> 
> You literally say that the loop runs, *or else* (xor) the else block 
> runs.

Nope, I'm not saying that. I'm saying that if loop can run, it runs.
Else if it can't run (which happens when it's exhausted), then "else"
runs. The only unclear thing here is that "break" skips it. That's not
immediately obvious, but if you think about, it starts to make sense,
because otherwise no "else:" would be needed at all.

And I'm saying that not in justification of "else:", but as an example
of learning how to understand what made the language author chose
"else:" as the name of that clause. The above aren't my words either,
that's what I read to grasp that stuff (and it stuck only when I peered
thru enough bytecode). If there is any obvious conclusion to make from
all that, that would be the same "Do Not Use" already mentioned.

On the topic of "change something", I'd personally wouldn't find it a
tragedy if:

---
for ...:
elif not break:
---

was made a synonym of

---
for ...:
else:
---


But I'm worried about the usual scope creep in the discussion here,
with all the further "if break/if empty/if not empty" adhoc clauses. And
I find "else:  # if not break" to be pretty neat already, just need to
crusade to make linters require it by default, as a second choice after
unconditionally warn on using "else:" in the first place.

Note that you'll need to make linter-crusade even if "elif not break:"
is adopted, because "else:" stays put, for backward compatibility.


-- 
Best regards,
 Paul                          mailto:pmis...@gmail.com
_______________________________________________
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/V53KMM5B2G5WF47Y3BLXRJEBSXC4ZNCU/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to