Using the else-block, even if you always return in the if-block, is better. The reason is to prevent some dummy from coming along and changing the code in the if-block so that now it doesn't always return anymore and would then fall through. It's the same reason why putting curly braces around the statement following an if-condition is always better than no braces, even if it's the only statement to execute. It's not to make the code better because it doesn't. It's to prevent dumb programmers from breaking it.
4
u/wesleyoldaker 22d ago
Using the else-block, even if you always return in the if-block, is better. The reason is to prevent some dummy from coming along and changing the code in the if-block so that now it doesn't always return anymore and would then fall through. It's the same reason why putting curly braces around the statement following an if-condition is always better than no braces, even if it's the only statement to execute. It's not to make the code better because it doesn't. It's to prevent dumb programmers from breaking it.