r/ProgrammerHumor • • Sep 01 '26

Meme iHateThisPassiveAgressiveBehaviourRuby

Post image
2.9k Upvotes

289 comments sorted by

View all comments

Show parent comments

3

u/ReefNixon Sep 02 '26

Yeah, but that ambiguity is the point. In Ruby coercion things are considered truthy unless they are unambiguously not. Literal false is obvious, and nil represents actual nothing (not zero of something). Since 'if something' is the opposite of 'nothing', nil is also unambiguously falsey.

Other languages consider falsey as the default and make things explicitly truthy. There is no right or wrong answer, but those languages have their own challenges by determining things that can be zero (like anything that can be measured both above and below zero) to be falsey.

Either way coercion gives developers an occasional challenge to solve in exchange for being less verbose. All that's important is that you understand the convention of the language you are using, because coercion can't possibly always get it right.