Hello,

On Tue, 21 Jul 2020 17:48:35 -0700
Christopher Barker <python...@gmail.com> wrote:

> how about:
> 
> for something in some_iterable:
>     some_stuff_with_maybe_a_break
> else if not break:
>     something_more
> 
> No new keywords :-)
> 
> or:
> 
> for something in some_iterable:
>     some_stuff_with_maybe_a_break
> else:  # if not break:
>     something_more

This is the most genius solution posted to this thread.

And if the thread didn't die after van Rossum's post, I don't cheer
hopes it would die now, but let me sprinkle in another "fresh"
thought. First let me remind how this thread started:

> ELSE-clause in FOR and WHILE has unclear syntax. I suggest new clause
> instead   

Then various people started to throw in variants of even more unclear
and confusing syntax (like "if" after "for"), with some percentage of
those people demonstrating not understanding how the original "else"
works.

But consider following idea: if it's confusing, DO NOT USE it. You
don't hear that often, but: treat Python as a generic programming
language, not as a bag of tricks. The fact that most other languages
don't have extra clause after "for" is enough of a reason to not use it
in Python either.


So why it exists at all then? It's there for people who don't find it
confusing, for very responsible use. As a random example, after
studying 2 (bytecode) Python compilers and having written my own (so I
know what code is generated from for-else), I no longer find it
confusing. I actually found 2 intuitive ways to use that construct, in
the very compiler mentioned - after all, if you eyeball a Python
compiler, you either know, or ready to learn, how all language
constructs work.

For anything else - clear ban. Everyone should consider that too. (But
please leave the language syntax alone (backwards compatibility, etc.),
at least that's a suggestion which comes out from van Rossum's post).

> As for the "loop didn't run at all" case: Does anyone find a need for
> that? Personally, I've found that everytime I do some kind of check
> for an empty iterable before a loop, it was totally unnecessary.

I find the need for that regularly. And I use the obvious syntax which
everyone else uses:

if not seq:
    print("This page is intentionally left blank")
else:
    for i in seq:
        ...

Any adhoc, confusing syntax someone may imagine to add, would go to the
same "DO NOT USE" category. So, I pray to van Rossum's answer that
something like that will never be added to the language. (Which is
hard to hang hopes on, given all the mess added recently.)

[]

-- 
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/GMSZRJP2VQDHK4C2ITWL2DZO7P6JMVY3/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to