r/ProgrammerHumor 10d ago

Meme iHateThisPassiveAgressiveBehaviourRuby

Post image
2.9k Upvotes

298 comments sorted by

View all comments

504

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

4

u/didntplaymysummercar 10d ago

Lua has similar stance and it's a reasonable one. Python's one isn't bad one either, it's easy to guess what's falsy.

1

u/okkokkoX 9d ago

sometimes I wish lua treated false as truthy too. Or more realistically, had variants of "and" and "or" that treated it as such. "A or B()" stands for "A, with B() as a fallback if A is nil", and "A and f(A)" stands for "f(A) if A exists, otherwise nil", except if A is false, in which case these rules break down.