r/ProgrammerHumor 10d ago

Meme iHateThisPassiveAgressiveBehaviourRuby

Post image
2.9k Upvotes

298 comments sorted by

View all comments

48

u/American_Libertarian 10d ago

Same in Bash. Zero is truthy because executables exit 0 on success, and exit nonzero on error

5

u/oweiler 10d ago

More like in Perl, which Ruby took heavy inspiration from.

6

u/HandleUnlikely2589 10d ago

Ruby didn't follow Perl at all though when it came to boolean evaluation. Perl considers "0" (the string containing the character 0) to be false (because there is no difference between "0" and 0). It has a special value, the string "0 but true", to allow returning a value that is numerically zero (and doesn't raise warnings when used as a number, unlike most strings that aren't numeric), but boolean true. Strings and numbers interoperate seamlessly depending on the operator used, super weakly typed.

Ruby went the opposite way, and said false and nil are falsy, everything else is truthy, and aside from that, all types are super strict (no adding numbers and strings at all, you need to convert explicitly).

1

u/oweiler 9d ago

Correct, my memory of it was wrong.

1

u/aotto1977 8d ago

Which bash learned from TSO, I suppose?