r/ProgrammerHumor 23h ago

Meme iHateThisPassiveAgressiveBehaviourRuby

Post image
2.6k Upvotes

276 comments sorted by

View all comments

453

u/deceze 23h ago

It's been a while since I've touched Ruby, but I think the stance was that only false and nil should be falsey? Which is not an unreasonable stance to take. The fewer falsey values, the easier it is to predict the behaviour. It's just surprising when coming from other languages.

Just off the top of my head, PHP treats "0", that is, specifically a string with a single zero, as falsey. Which has clearly gone too far to the other extreme.

20

u/DeepDay6 22h ago

That's in fact a very legit take that e.g. Clojure also takes. It makes reasoning much easier and also eliminates WTF moments like reading if (myArray.length) which to any sane individual might appear like duck typing but is a hack to save those keystrokes > 0, in the hope that no one manually set it to a negative value, which is truthy as opposed to zero, and so on.

14

u/Original-Ad-8737 22h ago

Array length has to be an unsigned integer so is you manage to set it to a negative value you deserve the pretty explosion of your code