3 ms·
I think he means that when you see a block of straight non nested code, you assume it can be yanked out or moved around without penalty. That is, the conditions
by dsego 8y ago
I think he means that when you see a block of straight non nested code, you assume it can be yanked out or moved around without penalty. That is, the conditions and the actual code are not visibly connected and you have to trace the dots.
But when it's nested it's immediately more clear that the nested code depends upon some conditions.
- aw1621107 8y agoThat'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.