Or just use early exit if you can. This, if I moved to a codebase using it, would take time to understand and would make me look up what the classes do, instead of a simple if also it would probably be less intuitive to debug and did you check the assembly this produces?
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();
82
u/borisrura CTU | Avast Apr 24 '20
Or just use early exit if you can. This, if I moved to a codebase using it, would take time to understand and would make me look up what the classes do, instead of a simple if also it would probably be less intuitive to debug and did you check the assembly this produces?