DEV Community

Discussion on: A simple tip for cleaner code

Collapse
 
whoisryosuke profile image
Ryosuke • Edited

I tend to use the second example a lot in code that isn't large or repetitive enough to be abstracted, and I don't need to return a value immediately. That way I can also intercept the value before it's returned a couple times, and run other checks if necessary.

The final example is a little more elegant, but makes presumptions about the situation. Ideally we'd all do that, but then we'd also have one-off functions for logic that's singular in occurrence.