Breaking/continuing out of multiple loops

I don’t agree with the premise that “you would have [refactored] already” here. In large codebases with many contributors it can be common that over time the body of a loop will tend to grow as more and more gets added but no one chooses to refactor it until their hand is forced in someway. Perhaps the original decision not to have a single use function was not unreasonable at the time it was made. Later on though as more and more code is added it gets clearer and clearer that it should be refactored but at the same time the more it grows the harder it gets to actually do the refactoring. The reason I dislike the idea of labelled break is probably for precisely the opposite reason that you want to propose the idea: I don’t want to provide more opportunities to postpone what I would consider to be the necessary refactoring (that very often should have been done a long time ago).

I can’t actually picture in my mind real maintainable code where labelled break is significantly better than a reorganisation. When I try to imagine this being used in practice I just picture it being used to extend the kind of spaghetti code that I already wish people didn’t write in the first place. Perhaps I don’t have the imagination to see the kind of situation where this could be used in a good way but I can definitely imagine it being used in a bad way.

Of course if real life examples were provided then we could discuss the pros and cons in those cases without depending on my imagination.

2 Likes