Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>@<a href="https://stackoverflow.com/questions/15851/refactoring-away-labeled-loops#15946">Sadie</a>:</p> <blockquote> <p>They all look less readable than the original, in that they involve spending more code on the mechanism of the code rather than on the algorithm itself</p> </blockquote> <p>Externalizing the second loop outside the algorithm is not necessarily less readable. If the method name is well chosen, it can improve readability.</p> <blockquote> <p>Some of them are broken, or were before they were edited. Most damning is the fact that people are having to think quite hard about how to write the code without labels and not break anything.</p> </blockquote> <p>I have a different point of view: some of them are broken because it is hard to figure out the behavior of the original algorithm.</p> <blockquote> <p>Some come with a performance penalty of running the same test twice, which may not always be trivial. The alternative to that is storing and passing round booleans, which gets ugly.</p> </blockquote> <p>The performance penalty is minor. However I agree that running a test twice is not a nice solution.</p> <blockquote> <p>Refactoring the relevant part of the code into a method is effectively a no-op: it rearranges how the code is laid out in the file, but has no effect on how it's executed.</p> </blockquote> <p>I don't see the point. Yep, it doesn't change the behavior, like... refactoring?</p> <blockquote> <p>Certainly there are cases where labels are used incorrectly and should be refactored away. I just don't think it should be treated as some unbreakable rule.</p> </blockquote> <p>I totally agree. But as you have pointed out, some of us have difficulties while refactoring this example. Even if the initial example is readable, it is hard to maintain.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload