5 ms·
> Break from labeled blocks is a pretty niche thing. I can remember a few cases it would have been useful, but I'm not sure I'll remember the feature exists nex
by pavon 4y ago
> Break from labeled blocks is a pretty niche thing. I can remember a few cases it would have been useful, but I'm not sure I'll remember the feature exists next time it comes up.
Yeah, I feel like the vast majority of the time this would be better handled by splitting out that block into a function. There are situations where there the number of parameters needed to pass in would get unwieldy, but that is where I start thinking about if all that loose state is intrinsic to the problem, or a sign that I need to refactor my datastructures.
- zozbot234 4y ago> Yeah, I feel like the vast majority of the time this would be better handled by splitting out that block into a function. It's a nice idea, and Rust supports "local" fn definitions inside blocks so it would be quite elegant as well.
- edflsafoiewq 4y agoThe borrow checker is "smarter" within a single function body though, so factoring code into a separate function is not necessarily as easy as in other languages.
- Ar-Curunir 4y agoYou can use it with a closure to get the best of both worlds
- saghm 4y agoI ran into this issue years ago (possibly even before labeled exit from loops or even NLL, although I'd have to dig through some old code to confirm this). I had some logic that I wanted to short-circuit, but moving everything to a separate method call would have required an extra borrow that would not have been allowed. I don't think that I'll end up needing to use this feature much, but I'm glad to finally have it as an option for the rare cases when it will improve the readability of my code.
- mjw1007 4y agoOne reason to support this sort of feature is that it makes it easier to split changes into two reviewable steps: first make a minimal change that introduces some ugly thing like break-with-label, then clean it up with a no-change-of-behaviour commit.
- insanitybit 4y agoLike with GAT, I think one of the major reasons to support this feature is because it feels consistent. "I can put generics here, but not there? I can break here but not there?". I've run into "accidentally" writing the equivalent of GAT before just because I had expected it to work.
- PointyFluff 4y agoI imagine this is to make Torvalds happy.
- steveklabnik 4y agoThe RFC for this feature was proposed in 2017, and accepted in early 2018. Implementation landed shortly after. Nothing to do with Linus.