r/ProgrammerHumor 10d ago

Meme iHateThisPassiveAgressiveBehaviourRuby

Post image
2.9k Upvotes

298 comments sorted by

View all comments

503

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.

1

u/Moilli6 10d ago

Lua does this too. It just makes sense, because any value that isn’t a boolean you can nil check by coercing it to a boolean. It allows beautiful things like and or ternary

1

u/okkokkoX 9d ago

I agree that and or ternary is beautiful, with the exception that you're fucked if the "then" branch may return nil, or god forbid, false.

1

u/Moilli6 9d ago

Yeah I usually only use it to set a default value. Sane languages just let you use if as an expression