3 ms·
> put a copy of the second half of the loop before the `do` But why is that better than just using a goto? Goto’s are usually discouraged because they make cod
by bazoom42 3y ago
> put a copy of the second half of the loop before the `do`
But why is that better than just using a goto? Goto’s are usually discouraged because they make code hard to follow, but if avoiding the goto makes the code even more convoluted, whats the point?
- II2II 3y agoGiven that exposure to `goto` is going to be minimal born most developers born after 1980's, the use of `goto` is likely to appear more convoluted. At any rate, the greatest danger in this case lies in the code duplication. If performance is not an issue, stick it in a function. If performance may be an issue, start off by sticking it in a function and see if compiler optimizations take care of the issue. If performance is an issue, by all means force it to do what you want by using `goto`. While there is nothing intrinsically evil about `goto`, most of the developments in programming languages were meant to overcome challenges of the past. We shouldn't dump those developments based upon exceptions to the rule. Rather, we should recognize exceptions to to rule as being extraordinary circumstances in which those developments were not useful.
- bazoom42 3y ago> start off by sticking it in a function and see if compiler optimizations take care of the issue. You could also just use a goto and avoid the accidental complexity. I still dont understand why a complicated workaround is better than a simple goto.