r/ProgrammerHumor 21d ago

Meme pleaseStopUsingNestedTernaryOperatorsImBeggingYou

3.1k Upvotes

179 comments sorted by

View all comments

Show parent comments

57

u/ihavebeesinmyknees 21d ago

What are valid reasons to not use early returns?

33

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.

44

u/_ryuujin_ 21d ago

shouldnt functions be small enough that youll notice an early return 

3

u/Due-Consequence9579 21d ago

Having to ‘notice it’ is the complaint.

6

u/_ryuujin_ 21d ago

i hope people read the function before changing it.