2 ms·
Regarding the defer statements in loops. It is better to just not ever do that. Instead, move the defer outside of any loops, and have the defer check the stat
by tomohawk 8y ago
Regarding the defer statements in loops. It is better to just not ever do that.
Instead, move the defer outside of any loops, and have the defer check the state of the variable to decide action. For example, in the case of an open file, the loop should close the file and nil out the reference. In the defer, if the reference is not nil, it closes the file.
- masklinn 8y agoThe issue outlined in the article is not defer in a loop, it's defer in an infinite loop.