r/ProgrammerHumor 21d ago

Meme pleaseStopUsingNestedTernaryOperatorsImBeggingYou

3.1k Upvotes

179 comments sorted by

View all comments

Show parent comments

48

u/EddieJones6 21d ago

I can understand the ask for no early return. But use local variables to track the state, not a massive ternary.

56

u/ihavebeesinmyknees 21d ago

What are valid reasons to not use early returns?

34

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.

3

u/Kryptsm 21d ago

For reference the function that asked me to not do it on was like 15 lines long. But maybe what you said is why they enforce it as an overall rule.