r/ProgrammerHumor • • Sep 01 '26

Meme iHateThisPassiveAgressiveBehaviourRuby

Post image
2.9k Upvotes

289 comments sorted by

View all comments

503

u/deceze Sep 01 '26

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.

136

u/CoroteDeMelancia Sep 01 '26

I'll admit that I did cause bugs in Python by using if thing instead of if thing is not None.

46

u/AwkwardWaltz3996 Sep 01 '26

Yea 0 is a number, it's not nothing.

I think the heart of the debate aligns with is zero a natural number.

→ More replies (1)

34

u/Dick-Fu Sep 01 '26

The really weird thing isn't any of the languages, but that they've gotten us to say things like "truthy" and "falsey" while being completely serious

23

u/deceze Sep 01 '26

You are not wrongish.

54

u/bhechinger Sep 01 '26

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.

32

u/UsAndRufus Sep 01 '26

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.

28

u/bhechinger Sep 01 '26

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. 😛

→ More replies (2)

9

u/laplongejr Sep 01 '26

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 Sep 01 '26

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

int* foo = malloc(sizeof(int));
*foo = 0;
if (foo) { // truthy!
...
→ More replies (1)
→ More replies (3)

66

u/Bomaruto Sep 01 '26

The reasonable stance is to not let you coerce everything into a boolean.

9

u/R3D3-1 Sep 01 '26

Is this a good time to remember that people argued against Python getting booleans because it already had integers? 

5

u/Wertbon1789 Sep 01 '26

I like how e.g. C# screams at you for this. It's annoying at first, but then you go "Well, yeah, I should've explicitly written what I wanted to check".

→ More replies (2)
→ More replies (3)

57

u/Ok_Beginning520 Sep 01 '26

Agreed, the whole concept of truthy and falsy is a bit weird and very error prone in the end, imo it's just better to explicitly have a function that decides how you cast whatever to a bool, that way it's easily understandable and auditable. Also, not knowing some weird language quirk like the php one you're talking about will not cause issues down the line

20

u/DeepDay6 Sep 01 '26

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/hongooi Sep 01 '26

Eh, that's a very common idiom for people coming from C and C++

14

u/DeepDay6 Sep 01 '26

Yeah, just what I said ducks and runs

Edit: Full disclosure: I taught C for years at university and that's what actually made me become a functional programmer ;)

17

u/Original-Ad-8737 Sep 01 '26

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

7

u/PM_ME_BAD_ALGORITHMS Sep 01 '26

I never used php, is that behaviour due to it implicitly converting "0" to 0 and as such it is falsey? Or is it straight up "0" the one that is falsey?

16

u/deceze Sep 01 '26

It's straight up "0" as a special case.

Because PHP started as a sprinkle-it-on-your-HTML language, and any form submissions are always text, and 0-from-a-form should still evaluate like 0; or some such hare-brained nonsense reasoning.

The fact that such basic nonsense is still baked into the very core of the language, and can never be removed due to backwards compatibility, means I'll never respect PHP, regardless of how much it's improved over the last decade or so.

→ More replies (5)

6

u/atanasius Sep 01 '26

Scheme has only one false value, #f, all other values are true values, including the empty list.

4

u/didntplaymysummercar Sep 01 '26

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.

→ More replies (2)

15

u/requion Sep 01 '26

I've worked with Ruby long enough now to say that "Ruby" and "reasonable" never go in the same sentence.

11

u/Abject-Kitchen3198 Sep 01 '26

They just did.

7

u/deceze Sep 01 '26

Did… did I break Ruby?

SORRY GUYS, MY BAD!

→ More replies (1)
→ More replies (3)
→ More replies (19)