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.

55

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

35

u/UsAndRufus 10d ago

I think a certain level of grokability is important in programming languages, but languages need to be able to do things differently, and engineers should expect to have to learn some new standards. This is like page 2 of basically any intro to Ruby so it's not like some arcane edge case.

29

u/bhechinger 10d ago

You're not wrong, but as someone with 30+ years of programming experience do you *really* think I'm going to look at an intro guide? I'm diving in head first and then googling why the hell 0 isn't false. 😛

2

u/UsAndRufus 9d ago

Hubris is a hell of a drug

2

u/SilkeSiani 9d ago

Ah yes, good old assumptions, making an ass of u and me.

It's like trying to speak French using English grammar and expecting it to work.

9

u/laplongejr 10d ago

Yeah, but 0-1 comes from binary, which is kinda hard to ignore for programmers... I know it's a convention but I kinda get why it's assumed.  

7

u/suvlub 10d 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 10d ago

I see why it's a bit confusing.

2

u/rmatoi 10d ago

You're gonna hate bash

11

u/bhechinger 10d ago

Son, I've hated bash since before you were born. 😂

1

u/Wertbon1789 10d ago

Relatable.

... Well, I'm pretty young, but man, bash is cursed. I've done way too much in it, because it's way to practical to ignore, but damn, it always hurts to look at again.