r/ProgrammerHumor 23h ago

Meme iHateThisPassiveAgressiveBehaviourRuby

Post image
2.6k Upvotes

276 comments sorted by

View all comments

452

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

63

u/Bomaruto 22h ago

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

8

u/R3D3-1 12h ago

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

5

u/Wertbon1789 13h ago

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

1

u/didntplaymysummercar 11h ago

C#, and Java (where C# got it from, probably), Go and Pascal, Rust and Haskell (I mean, with those two's type systems, imagine they didn't forbid it.. lol), it's not even uncommon.

1

u/Wertbon1789 7h ago

Didn't say it was. C# was just the first example that came to my mind.

9

u/suvlub 19h ago

If I may be pedantic, not to coerce without you asking. A language that wouldn't let me simply convert between types sounds annoying

29

u/theturtlemafiamusic 18h ago

"Type coercion" is when it's done without asking. Otherwise it's just type conversion / casting.

6

u/ntfaw 18h ago

It's not that you couldn't convert between types, it's that it wouldn't be automatic. You would need to actively call toboolean on a value before using it as a boolean, and the idea behind that is that intentionally casting the value leads to fewer mistakes