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

With early returns, there are no context shifts. You're just getting rid of contexts as and when they are looked at. So there's no question of keeping a stack of context in mind.

What you say works well when you can physically see the structure in the code. With deep nesting in large functions, you can't - it's easy to get lost in it.

That said, I can understand what people say about multiple returns leading to bugs in refactoring - personally, I always prefer early and multiple returns to nested code, and I've developed the habit of checking the full function for any exit points whenever I refactor it.

To each his own, I guess.



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

Search: