Re:Early exit is a tail call optimization of procedural lang...
by SideburnsOfDoom on Monday December 14, 2015 @11:01AM
(#10731744)
> What if you have to introduce a modification to your logic that applies a transformation to the result? Should you modify it in 5 places, or 1?
In 1 place, clearly. The multiple-return version would require a bit more refactoring at this point, either extracting another method or introducing the "return value" state var at that point.
Why not code it with single return up front? Simple: most likely, You Aren't Going To Need It. The YAGNI principle says to make the code more complicated when you need to, not before.
In 1 place, clearly. The multiple-return version would require a bit more refactoring at this point, either extracting another method or introducing the "return value" state var at that point.
Why not code it with single return up front? Simple: most likely, You Aren't Going To Need It. The YAGNI principle says to make the code more complicated when you need to, not before.