Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


Absolutely 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: