DEV Community 👩‍💻👨‍💻

Discussion on: Why we shouldn't use "else"

scott_yeatts profile image
Scott Yeatts

I once argued AGAINST early return, but then I tried it and I can't imagine why I didn't use it before.

Early on in my career (a long time ago in a galaxy far far away and all that) I had been taught a rule that a function should only ever have one return in order to make it clear what was being returned, and I clung to that rule for too long.

It's one of the best changes I've made to my code style in years. I love it.

patricktingen profile image
Patrick Tingen • Edited on

I was taught exactly the same thing, but when you adhere to that you end up with massive blocks. Early return is king!