3 ms·
That's an interesting point. I'm not entirely sure I agree with that reasoning for early returns, though. If I'm extracting code to be available for more gener
by aw1621107 8y ago
That's an interesting point. I'm not entirely sure I agree with that reasoning for early returns, though.
If I'm extracting code to be available for more general use, I usually prefer to try to forget the preconditions of the source function and apply just the preconditions that are applicable for the now-standalone code. In that case, once I'm done with the extraction I'd need to ensure that the preconditions of the source function match the preconditions of the extracted code, and nesting doesn't really affect that; if anything, having the preconditions all up front would make things a bit easier by having everything in one place.
As for moving blocks of code around, I can't say I've had much need to move code across "precondition domains", for lack of a better term. Perhaps I just haven't run across the right situation yet.