3 ms·
>avoid early returns because they can be confusing It seems to me like the exact opposite is true. Early return conditions stand out in your code and so the st
by hackinthebochs 7y ago
>avoid early returns because they can be confusing
It seems to me like the exact opposite is true. Early return conditions stand out in your code and so the structure matches the flow. Its much clearer than having error state weaved through the mainline behavior of the function.
I'm pretty sure the pattern of having only one return is popular among older engineers because it makes it easier to use pre-condition/post-condition/invariant style reasoning which used to be popular. Outside of this scenario I see no reason to avoid early returns.