by jemfinch · 14y ago · 0 comments
if (UnexpectedOrUnhandledCondition(x)) {
...
return false;
}
if (OtherError(y)) {
return false;
}
and so on. Serial code like that is trivially easy to understand when reading; more importantly, six months later, it's far more explicit and easier to comprehend than the comparable single-exit version.The alternative to early exits is nesting, and nesting is the readability killer. My experience has apparently been just the opposite of yours: that avoiding early exits is a sign of a junior programmer, and returning early whenever possible is a sign of an experienced programmer who knows that understands code maintenance.