3 ms·
I don't dispute that your argument has merit, but I disagree. An early exit from a function is an instance of "flat is better than nested" -- that is, it's oft
by peterhunt 14y ago
I don't dispute that your argument has merit, but I disagree. An early exit from a function is an instance of "flat is better than nested" -- that is, it's often easier on the brain to not have to keep track of different layers of nesting. I often use early exits just to get rid off edge cases so the rest of my (non-nested) function can just deal with the "normal" case.
- untog 14y agoAbsolutely agree. if (a == null) return false; stuff(); is considerably better than if (a != null) { stuff(); } Especially once you start dealing with a ton of these cases.