<@UA7S0965Q> I'm not sure what you mean by "reason...
# suitescript
e
@Caleb Fong I'm not sure what you mean by "reason to do that early return". My guess is that in my example I wrote it that way, but in that case it's not an "early" return because my function had nothing to do after that, so the return was right on time 🙂
🙂 1
c
Thank you for the clarification @erictgrubaugh! I saw "early return" on some JS blogs and it seems to mean "get the results back as soon as it is useful". Which as you pointed out, in your example function
return
was the point, and it wasn't going to do more. I feel like 💡 is going off in my head, now.
s
there's other schools of thought that suggest a function should only have a single return and that should be at the end of the function. I don't necessarily subscribe but the idea is to not have multiple ways/places a function can terminate.
e
Yes, there is definitely a lot of people who subscribe to the "single entry, single exit" pattern for functions. Personally, I hate it 🙂 but that shouldn't stop anyone else from using it if that fits their situation better
s
I tend to use very small functions so either way is trivial to read because the entire function is maybe 4 lines of code.
e
I do this as well
If I have a function exceeding a dozen or so lines, I've done something horribly wrong
s
I also use NFT, which can often lead to a 70% reduction in code while improving readability, so that helps too.
(with keeping functions small but still do something significant 🙂 )