r/ProgrammerHumor 19h ago

Meme iHateThisPassiveAgressiveBehaviourRuby

Post image
2.4k Upvotes

266 comments sorted by

View all comments

53

u/redlaWw 19h ago

Same in Lua. Only nil and false are treated as falsy, everything else is treated as truthy. The idea is that by default everything that is not nil is treated as true because it exists, and false is a special case used to represent false propositions.

It can be a bit of a stumbling block coming from some other languages, but the rule is so simple that you get used to it quickly.

7

u/NotDuckie 15h ago

Imagine having rules for what should be truthy and falsey instead of just rolling dice every time.

3

u/Tsu_Dho_Namh 12h ago

I love it tbh.

"If (variable)" is a fantastically clean way to check if the variable isn't nil.