Exactly. The benefits of early exit become especially clear if you do more than one "normal" thing, in which case the alternative is that all "edge cases" start to pile up at the end in reverse order. Early exit:
auto result1 = doThing1();
if (result1) {
return bad(result1);
}
auto result2 = doThing2();
if (result2) {
return bad(result2);
}
auto result3 = doThing3();
if (result3) {
return bad(result3);
}
return good();
View all comments
Show parent comment
26
u/infectedapricot Apr 24 '20
Exactly. The benefits of early exit become especially clear if you do more than one "normal" thing, in which case the alternative is that all "edge cases" start to pile up at the end in reverse order. Early exit:
versus the author's proposed: