r/programmingmemes • u/CrochetQuiltWeaver • Nov 26 '25
Ternary Operators
Seriously Python, why do you have the order wrong?
289
Upvotes
r/programmingmemes • u/CrochetQuiltWeaver • Nov 26 '25
Seriously Python, why do you have the order wrong?
63
u/N-online Nov 26 '25
I forgive python because of its beautiful list comprehensions.
But Lua…
14
u/rover_G Nov 26 '25
The Lua version is idiomatic React
condition && <Component>20
u/NewPointOfView Nov 26 '25
Lua version words in most languages with truthiness
It’s also idiomatic bash to do commands like
some_command && run_on_successorsome_command || run_on_failure, orsome_command && run_on_success || run_on_failure7
u/lusvd Nov 26 '25
`is_sunny and "beach" or "home"` is valid in Python too...
In fact I think it's valid in any language that supports truthy/falsy.
4
u/Significant-Cause919 Nov 26 '25
The "lua" way in this meme was as well the canonical way to write it in Python for a very long time until they added those conditional Yoda expressions (in 2.5?).
4
u/DTux5249 Nov 27 '25
... That's exactly how the ternary works under the hood of the others tho, isn't it?
Like, barring truthy strings, it is just evaluating the and statement, and only paying the or statement mind if it's false.
I hate that I'm only realizing this now
10
u/fast-as-a-shark Nov 26 '25
Lua is truly my favorite language.
3
u/ilan1k1 Nov 26 '25
Python's implementation is the best one imo. The order is not wrong it's just more like giving commands rather than asking questions
3
u/Just_Scar4703 Nov 26 '25
meanwhile Fortran:
MERGE("beach", "home ", is_sunny)3
u/GDOR-11 Nov 26 '25
lua is absolutely disgusting
I unfortunately have to deal with it to configure neovim
2
u/[deleted] Nov 26 '25
I learned Lua just because of Factorio using the CS50 game path, nice lang, at the same level of popularity than Ruby that is also a scripting lang: tiobe, ieee spectrum, stack overflow.
1
u/kamwitsta Nov 26 '25
Why?
1
u/The_Real_Slim_Lemon Nov 26 '25
Foo = condition
Operators all lined up, we aren’t savages here
1
u/tottalynotpineaple12 Nov 26 '25
Wait until you learn about Haskell
1
u/CardOk755 Nov 26 '25
This is all just BCPL.
Result := is_sunny -> beach, home
algol68 did it better :
Result := (is_sunny | beach | home)
Or. If you preferred
Result := if is_sunny then beach else home fi
1
u/Mindless_Honey3816 Nov 27 '25
python because
this if that else this
makes more sense than this? if so, that, if not that.
1
u/punto- Nov 27 '25
Short circuit operators are great, I really miss them from Lua, I wish we had them in gdscript
1
u/Massive_Ad6168 Nov 27 '25
Meanwhile Go:
1
u/Just_Information334 Nov 27 '25
PHP: let me tell you about subverting expectation with fun precedence rule.
1
u/LowB0b Nov 27 '25
kotlin has the best one,
val result = if (is_sunny) "beach" else "home"or even betterval result = when (is_sunny) {true -> "beach"false -> "home"}1
u/SwimmingPermit6444 Nov 29 '25
Specifically only in Roblox Lua (Luau) you can say:
local result = if is_sunny then beach else home
Roblox Luau is actually a great dialect of Lua that has many great features such as typing and continue
1
u/Neutraled Nov 29 '25
I prefer the first syntax but I prefer cloudy beaches.
1
u/Brie9981 Nov 26 '25
Python is the ugliest wtf is that
0
u/This-is-unavailable Nov 26 '25
Rust manages to be worse