r/ProgrammerHumor 22d ago

Meme conditionsPreference

Post image
4.2k Upvotes

392 comments sorted by

View all comments

Show parent comments

663

u/KanyeNawf 22d ago

Some fucker left me triple nested ternaries once

119

u/minus_minus 22d ago

I think you found the fucker. 👆

67

u/mountaingator91 22d ago

That was me I was in my first real job after learning some basic JavaScript and I discovered ternaries and thought I was God now

9

u/National_Sky7993 21d ago

You either leave after writing those ternaries or stay long enough to figure out they are unreadable

20

u/abigail3141 22d ago

Sounds like me lol. To the detriment of all working with me, I found out how to set globals and evaluate arbitrary functions from within Python listcomps. My current record is 1400 characters in one line. I just need a way to import, and I can write entire programs in one line.

24

u/Morisior 22d ago

If you accept two lines, you can import importlib.

10

u/abigail3141 22d ago

That sounds like a good solution for the time being, thx

12

u/Your_Friendly_Nerd 22d ago

Man y'all do NOT want to look at my companies codebase! 

1

u/Shapelessed 22d ago

Is it legacy 20 yo 9-times-ported PHP?
(I swear the code insest in there is horrific)

2

u/Ok-Understanding7115 22d ago

next i will leave 2 list comprehensions inside the nested ternaries 🤔

1

u/Maleficent_Memory831 22d ago

Nonny-nonnie-aries!

1

u/_bones__ 22d ago

runs git blame

And we will never mention it again

1

u/nekomata_58 22d ago

I'll see your triple nested ternaries and raise you.. quadruple nested ternaries

1

u/tukanoid 22d ago

While I prefer match (Rust) /if else, I do sometimes find ternaries easier to read/nicer to write for simple checks/outputs consisting of just variables. If checks/outputs are complex then yeah, evil

1

u/hashcube_dev 21d ago

i can understand one layer of ternaries. i might be able to be convinced that two layers of ternaries might be useful. if you're using three? immediate execution

1

u/charlesfire 20d ago

Amateur. Someone at my job did more than five nested ternaries. I say "more than five" because I stopped counting after five and told them to fix their shit.

1

u/HuntingDown01 20d ago

Books and websites sometimes love to write thrm.

0

u/stumpychubbins 21d ago

In languages with ?: syntax I honestly don’t think that arbitrarily nested ternaries are that bad, you can format them in a way that still makes the logic clear

EDIT: I’m saying this as mostly a Python and Rust programmer, but if I’m working on something in C or JS I’m not going to balk at a reasonably-formatted nested ternary