Timeline for Why does python use 'else' after for and while loops?
Current License: CC BY-SA 3.0
20 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Aug 19, 2024 at 14:18 | comment | added | Air | @Ed_ Great idea. I'll start commenting "after" on every block of code I write, to let people know that it will execute after the previous block has finished. | |
May 11, 2024 at 10:24 | comment | added | Ed_ |
nobreak is terrible. It's ambiguous: could mean if no break, could mean dont break in this block, or something else. And it's poor grammar. Should be after instead. After loop finishes, do this.
|
|
Oct 20, 2023 at 18:28 | comment | added | Jürgen A. Erhard | @zwol Which means it was exactly the thing Python 3000 was meant to do (and did, in many cases). | |
Oct 20, 2023 at 18:26 | comment | added | Jürgen A. Erhard | Thanks for the actual answer to the question. My take is that it's a symptom of the PHP-disease. Like PHP just included stuff from everywhere, and left the source naming conventions intact; camelCase, PascalCase, snake_case, whatever the source of some functions used, PHP used. Now I realize that Python, or rather Guido, wasn't immune to this. "We do for... else because Knuth did it". Same for continue. Both bad non-choices. And don't get me started on the return value of os.stat and the stat module. | |
Jun 19, 2022 at 16:41 | comment | added | chepner |
@zwol The new PEG grammar makes it easier to introduce new "context-sensitive" keywords (Python match remains a valid identifier in 3.10 even though it also introduces the new pattern-matching statement.) However, I do think the bar should still remain high for adding new keywords.
|
|
Oct 22, 2021 at 15:04 | comment | added | at54321 |
The # no break comment seems like a really nice idea to me. Only seeing else can be very misleading, as in 99% of cases else is related to an if , so adding a comment like that can be useful. That's what comments should be used for, after all - commenting non-obvious or potentially misleading stuff.
|
|
Aug 31, 2021 at 15:19 | comment | added | Jann Poppinga |
Though the example is incomplete because for ... else never makes sense without break .
|
|
Jul 12, 2021 at 22:00 | comment | added | zwol | "nobreak" would be a new keyword, and, as a rule, language designers are very hesitant to add keywords to an existing language, because it insta-breaks all code that has used that identifier for something else. | |
Dec 9, 2020 at 8:54 | comment | added | jaaq |
recent pep doc states that multiple ways is OK, just not multiple obvious ways. Since a nobreak keyword could be more obvious, maybe this is indeed a way to improve the syntax.
|
|
Nov 18, 2020 at 17:31 | comment | added | jaaq |
yeah that's true, but they did the same thing with the division operator, where one could import division from __future__ to replace / with standard division and add the // floor division operator.
|
|
Nov 16, 2020 at 19:50 | comment | added | Air | @jaaq I can't speak for Python core devs but consider the PEP 20 line "There should be one-- and preferably only one --obvious way to do it." | |
Oct 28, 2020 at 11:34 | comment | added | jaaq | Why not add support for nobreak next to else, have both be equal and exist alongside eachother and make a clear PEP style rule that nobreak should be used instead of else? | |
May 23, 2017 at 12:03 | history | edited | URL Rewriter Bot |
replaced http://stackoverflow.com/ with https://stackoverflow.com/
|
|
Jun 6, 2016 at 22:49 | history | edited | Air | CC BY-SA 3.0 |
Since pyvideo is going to die some time this year, let's link directly to the youtube video before anything breaks. While we're at it, direct link to the section of interest and update the post to use reference-style linking
|
Jan 29, 2016 at 22:53 | history | edited | Air | CC BY-SA 3.0 |
Good lord, don't start with this
|
Nov 2, 2015 at 18:40 | history | edited | Aaron Hall♦ | CC BY-SA 3.0 |
added 1 character in body
|
Oct 29, 2014 at 15:25 | history | edited | Air | CC BY-SA 3.0 |
explicitly reference other answer in case display name changes
|
Aug 19, 2014 at 19:10 | history | edited | Air | CC BY-SA 3.0 |
added 13 characters in body
|
Jul 15, 2014 at 15:07 | history | edited | Air | CC BY-SA 3.0 |
whoops
|
May 19, 2014 at 22:30 | history | answered | Air | CC BY-SA 3.0 |