Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

To me, the else isn’t intuitive if you haven’t encountered it before. It’s a nice feature, but perhaps better naming could improve code readability.

How about for-finally? It’s a hard thing to name correctly, but to me this seems to be slightly more intuitive if you’ve never seen the feature before.



You can’t use "finally" because that implies an expression that runs regardless, which this does not (it only runs if the loop never breaks).


Yeah, that’s a good point. To me it’s a little more clear than ‘else’ but there might be a better name still that doesn’t suggest this code always runs. Naming is hard :)


Perhaps `for...lastly...else`? `lastly` being the current meaning of `else` (something that happens after the iteration has completed), `else` being the thing I wish it meant (something that happens when the iterator was empty).


Finally would suggest it's always executed, even if aborted, like try...finally




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: