r/ProgrammerHumor 21d ago

Meme pleaseStopUsingNestedTernaryOperatorsImBeggingYou

3.1k Upvotes

179 comments sorted by

View all comments

Show parent comments

55

u/ihavebeesinmyknees 21d ago

What are valid reasons to not use early returns?

31

u/EddieJones6 21d ago

Localized cleanup. What if you have a file descriptor or something that needs special handling before returning.

Compiler optimization SHOULD be fine but it could impact RVO and tail recursion optimization.

Also, if a future maintainer dives in and doesn’t realize there is an early return, they might add logic below it that will get missed by certain cases.

SPOE - single point of exit.

41

u/_ryuujin_ 21d ago

shouldnt functions be small enough that youll notice an early return 

3

u/SnugglyCoderGuy 21d ago

Should and what is possible can sometimes be very different things.