3 ms·
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
by jordansmithnz 8y ago
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.
- detaro 8y agoFinally would suggest it's always executed, even if aborted, like try...finally
- makecheck 8y agoYou can’t use "finally" because that implies an expression that runs regardless, which this does not (it only runs if the loop never breaks).
- jordansmithnz 8y agoYeah, 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 :)
- mmebane 8y agoPerhaps `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).
- deleted 8y ago[deleted]