3 ms·
You're right that both technically qualify as early-return, which is why I qualified my original statement with "if you don't put the rest of the function in an
by brundolf 6y ago
You're right that both technically qualify as early-return, which is why I qualified my original statement with "if you don't put the rest of the function in an else clause".
In practice, in C-like languages, I tend to see the "else-less" version which is why I brought it up
- kbenson 6y agoIf you haven't seen it, Kevlin Henney's talk about "The Forgotten Art of Structured Programming"[1] is interesting (if somewhat long in the examples later), and somewhat related. It's not specifically about return early (and a case could be made that it should or should not apply specifically to early return), but it is about if, else, return, and how they affect cognitive load when reading code. 1: https://youtu.be/SFv8Wm2HdNM https://youtu.be/SFv8Wm2HdNM