Hacker News new | past | comments | ask | show | jobs | submit login

Well, most early returns are avoided mostly because it makes it harder to understand the code. But when you use guard clauses, like on your Linux Kernel example, you actually improve the code, because you reduce cyclomatic complexity (everything is now a linear path: a -> b -> c), you can reduce nesting, you can avoid unnecessary mutable state... so it's a win. The problem with early returns is when you use them in non-obvious places.

I believe that the majority of programmers agrees that using early returns for guard clauses is an okay exception.




Yes, I think really "avoid early returns" is an overextended special case of "avoid the nonobvious".




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

Search: