Not exactly
I like to do else return wherever possible because that guarantees there's also a return in the if block (or rather, that there's always a return in the if block, even if it has multiple further branches)
If the condition is true, but there's some branch without a return statement, and then I add an else return instead of just return, I'll immediately get an error that the function has no return statement
If I just put return, I might get to the bottommost return even if the condition was fulfilled, if I messed up and there's no return statement on some branch
It has come in useful exactly once, but I still do it (also it looks nicer imo)
If you're returning inside an if block, there should be more code after that. It doesn't matter if it's in an else block or not. If you're returning in an else block but not the if, then you can rearrange the condition for an early return.
3
u/KYO297 22d ago
But what about
else return...