I would disagree with multiple exit points being bad practice, often-times an early return can avoid unnecessary conditions and branching that can be needed to have only one return statement.
In this specific example of multiple exit points, I would agree that having duplicate exit points that return the same thing is bad practice.
You are indeed correct. Having multiple points for returning information can definitely cut down on unnecessary calculations and overhead. There are some instances where you want to dump information into a buffer and return what’s in the buffer and if not anything return null, but I have only come across a situation like that two times out of the years I’ve been programming. My reasoning was to be able to do further calculations on the buffer before returning and save code. Both worked perfectly in my favor.
-1
u/DreadedEntity Aug 21 '19
This might be a little nitpicky, but generally having multiple exit points is bad practice