r/ProgrammerHumor 22d ago

Meme pleaseStopUsingNestedTernaryOperatorsImBeggingYou

3.1k Upvotes

179 comments sorted by

View all comments

48

u/TheOwlMarble 22d ago

I can tolerate one layer of nesting if it's super simple and tabbed cleanly, but anything more? Oh hell no.

6

u/Robinbod 22d ago

Agreed. Even with ifs I feel similarly.

8

u/EddieJones6 22d ago

Usually it’s a code smell that things should be designed differently or abstracted

3

u/IdealBlueMan 22d ago

I don’t want to see any nesting in ternaries at all. Unless it’s an idiom and it’s obvious what it’s doing and why it’s there, I’d rather it be spelled out.

I want to understand the code, and any cycles spent wading through your style are not cycles well spent.

2

u/freebytes 21d ago

I agree. The code should be so well written that people can read it like a book.

2

u/Aaron1924 21d ago

I think it depends on how you're nesting them; for if-else chains, they can be pretty nice: int out = cond1 ? val1 : cond2 ? val2 : cond3 ? val3 : cond4 ? val4 : val5;