I'm a big Python user, but I'm -1 on for..else -- mostly because of the choice of the "else" keyword.
The issue is that it's downright misleading. You don't look at the 'else' clause and think "oh, I don't know what that means" & go look up the docs like you might with other unfamiliar parts of a new language. You make assumptions because of 'else's familiar semantics elsewhere in the language (i.e. "else" implies that the block is executed when the test fails). In the case of for..else those assumptions don't hold, and invariably lead to bugs. For this reason I never bothered to memorize the *real* behavior of for..else in Python, and never missed it. It's just asking for trouble. Call me a curmudgeon, but I think your code will be more explicit if you declare a mut bool & check its state post-`break`. :) Cheers, Tom On Sat, Aug 10, 2013 at 11:22 AM, Michael Woerister < [email protected]> wrote: > On 08/10/2013 07:24 PM, Paul Nathan wrote: > >> On 8/10/13 7:10 AM, Simon Sapin wrote: >> >>> Hi, >>> >>> Now that the for loop is based on external iterators, can we reconsider >>> "for-else"? >>> >>> Proposal: >>> >>> for i in iter { >>> // ... >>> } else { >>> // ... >>> } >>> >>> The optional else block is executed when the for loop stops without >>> exhausting the iterator, ie. when "break" is used. >>> >>> I spent quite some time in Python, delving into as much of the language >> as I could, and for-else was not something I used. It actually caused me >> a bug due to a mis-indented if block in the for loop. >> >> I would suggest that perhaps for-else belongs as a macro construct for a >> while to test adoption; if it proves useful and strongly adhered to, it >> could be moved into the core language? >> > +1 for a macro approach. > > ______________________________**_________________ > Rust-dev mailing list > [email protected] > https://mail.mozilla.org/**listinfo/rust-dev<https://mail.mozilla.org/listinfo/rust-dev> > -- *Tom Lee */ http://tomlee.co / @tglee <http://twitter.com/tglee>
_______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
