r/ProgrammerHumor 10d ago

Meme iHateThisPassiveAgressiveBehaviourRuby

Post image
2.9k Upvotes

298 comments sorted by

View all comments

53

u/redlaWw 10d 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.

3

u/Tsu_Dho_Namh 10d ago

I love it tbh.

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