Where did the notion of “one return only” come from?
softwareengineering.stackexchange.com
softwareengineering.stackexchange.com
A return statement IMO makes it much more clear that "yeah, we're done under this circumstance"
I think it comes from someone mistaking "keep it simple and easy to read" with "ALWAYS THAU MUST DO THIS AND NEVER THAT!"
Alas, the question actually describes a practice I've never seen nor heard of. Maybe I'm just too young.
Whether you use one or many return statements from a method written in a high level language would depend wholly on the nature of that method's implementation and context of use.
The code shown with the if with two returns I think adds cognitive complexity - there is no need for the else.
[0] is probably the best defense of the position I could find quickly, but the example used is convoluted, and very much "look what happens when you allow multiple returns".
I personally like to use early returns as guard statements when I'm doing precondition checking or on errors.
[0] https://spin.atomicobject.com/2011/07/26/in-defence-of-misra...
Actually, that probably ought to be avoided in most cases, come to think about it...