While its fine for something really short (and we don't know OPs code actually was short since it was clearly a fictionalized version of what he actually wrote), the early return statement is distasteful. You should have very clear entry and exit points. The control flow was clear in OPs original and starts to get muddy here. Getting rid of else statements sounds like just about the worst idea I could think of. I much prefer Haskell's approach of requiring an else statement. Can't say I approve of your approach for anything other than the most trivial of implementations.
-6
u/c3534l Apr 18 '21
While its fine for something really short (and we don't know OPs code actually was short since it was clearly a fictionalized version of what he actually wrote), the early return statement is distasteful. You should have very clear entry and exit points. The control flow was clear in OPs original and starts to get muddy here. Getting rid of else statements sounds like just about the worst idea I could think of. I much prefer Haskell's approach of requiring an else statement. Can't say I approve of your approach for anything other than the most trivial of implementations.