Re:Microfeatures I'd like to see in more languages
by skykooler on Thursday January 05, 2023 @10:02PM
(#34270427)
They also seem to be unknown to a lot of Python programmers unfortunately; I’ve had PRs rejected because a for-else loop was “unusual syntax” and therefore considered hard to maintain.
Re:Microfeatures I'd like to see in more languages
by thiht on Friday January 06, 2023 @08:24AM
(#34274304)
I used one recently in a script and they're definitely not that readable. It always takes some time what "else" means in the context of a loop.
I feel like it would work better with a more explicit keyword, but I don't know which one. `nobreak`?
Re:Microfeatures I'd like to see in more languages
by cpurdy on Saturday January 07, 2023 @08:08PM
(#34294923)
I hate the Python syntax using "else" for this, but I love the feature.
I've often wanted both a "then" and an "else" from both for and while loops. The "then" would be for a successful completion (no break), and the "else" would be for when the loop doesn't even run a single iteration.
But that didn't make it into our "language budget", unfortunately. It's easy to implement, but hard to argue for when it doesn't get used often
They don't come up that often, but when they do they're really the best solution.