r/ProgrammerHumor 17h ago

Meme iHateThisPassiveAgressiveBehaviourRuby

Post image
2.4k Upvotes

264 comments sorted by

View all comments

416

u/deceze 17h 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.

39

u/bhechinger 16h ago

I don't disagree with a smaller set of truthy values, but 50+ years of programming mainly treating 0 as false and 1 as true makes it an immediately confusing thing for anyone coming from a different language.

6

u/suvlub 14h ago

I think the logic is the analogous C code would be something like

int* foo = malloc(sizeof(int));
*foo = 0;
if (foo) { // truthy!
...

1

u/cyber2024 9h ago

I see why it's a bit confusing.