logoalt Hacker News

Heliodextoday at 1:38 AM1 replyview on HN

A comment <https://github.com/LuaJIT/LuaJIT/issues/1475#issuecomment-47...> has already been made on the issue regarding the ternary operator, recommending `if x then y else z` over `x ? y : z`. This is exactly how it's done with if-then-else expressions in Luau <https://luau.org/syntax/#if-then-else-expressions>, another language compatible with Lua, and makes it a ton easier to nest (especially with elseif) and I believe still easier to read than `y if x else z`.


Replies

mjcohentoday at 1:58 AM

The ternary operator is easy to nest if you put each clause on a separate line. Then it looks just like nested if-then-else.

show 1 reply