3 ms·
I agree with the other commenters, but I'll say that I understand the original intent of the rule was to avoid confusing logic, such as: if (x): do(thing1)
by ebiester 14y ago
I agree with the other commenters, but I'll say that I understand the original intent of the rule was to avoid confusing logic, such as:
if (x):
do(thing1)
y := do(thing2)
if (y):
do(thing3)
return 0
else:
return -1
else:
do(thing4)
return 0
___
As you can see, such logic could quickly become hard to test and reason about. Does a single return help all that much? Not in and of itself, but it does tend to make writing such code a bit more painful, leading to better designs. However, guard clauses are a superior design in general.
I still avoid multiple returns in my main logic when side effects are involved, at least when I can.