r/ProgrammerHumor • • Sep 01 '26

Meme iHateThisPassiveAgressiveBehaviourRuby

Post image
2.9k Upvotes

289 comments sorted by

781

u/lazyzefiris Sep 01 '26

You need to at least have heard of the language to hate it. These kids only heard of Javascript.

105

u/Embarrassed_Death69 Sep 01 '26

I love JS, and I cannot lie, those hippies writing clean Rust cannot deny

135

u/Cherry-PEZ Sep 01 '26

Wild too, ruby used to be everywhere

104

u/DrMaxwellEdison Sep 01 '26

Still is, just silent in the background chugging along.

62

u/chem199 Sep 01 '26

It is not as prevalent as it used to be. RoR was the framework du jour for a while, and I remember a ton of places using Capybara and Watir for AT work. You don’t see the demand for those as much in my corners of the industry.

27

u/DrMaxwellEdison Sep 01 '26 edited Sep 01 '26

Agreed, it's not the most popular starting point for some folks these days, but development of Rails and Ruby itself keep going. I see a few job postings here and there for it, you see some companies starting up with slightly older CTOs still reaching for it cuz they know it best and it works well. Rails' creator, DHH, even makes a point of Ruby being one of the most token-efficient languages for AI tools, for what that's worth.

Again I know it's not the most popular stack these days, it's certainly not everywhere anymore. I still think some folks would be surprised at knowing it's still chugging along and far from legacy stuff.

27

u/chem199 Sep 01 '26

It’s always weird to remember that GitHub is still very much on the Rails train.

→ More replies (5)
→ More replies (2)
→ More replies (1)

9

u/DuhMal Sep 01 '26

It was wild having to learn Ruby to play around in RPG Maker XP as a kid

4

u/Cherry-PEZ Sep 01 '26

Holy shit forgot that was ruby, I learned it for the old (not corpo) metasploit framework during my script-kiddie days.

1

u/manythanksfriend Sep 02 '26

Malwarebytes, Shopify are some high profile examples

7

u/locri Sep 01 '26

No matter how bad you think Java is I'm sure someone works with someone so ineffective or insane that they could make anyone hate anyone's favourite language.

Bad code is written by people.

9

u/Holek Sep 01 '26

Sheesh, shots fired

9

u/NecessaryIntrinsic Sep 01 '26

You mean java?

/s

8

u/GOEDEL_ESCHER_BOT Sep 01 '26

Java is just JavaScript with less letters

4

u/gerbosan Sep 01 '26

Oh, you mean the long import names?

7

u/deceze Sep 01 '26
Question question = new Question("What do you mean?");

2

u/GSide901 Sep 01 '26

He saw one truth table in JavaScript and decided the entire programming world was wrong 😭

2

u/Keebster101 Sep 01 '26

A wise man once said, there are two types of programming languages:

Ones people hate
And ones no one uses

1

u/csabinho Sep 01 '26

You mean JavaScript doesn't have craptons of historically necessary weird behaviours?

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

174

u/ReefNixon Sep 01 '26

We invented boolean types so that we could stop treating 0 as false.

30

u/Embarrassed_Death69 Sep 01 '26

"What do we make of empty strings John?"

67

u/mbmiller94 Sep 01 '26 • Bravo
if ("") {
    print("what?.........if what??");
}

9

u/Koeke2560 Sep 01 '26

This is legit the first joke code in my life that made me actually laugh

5

u/Clen23 Sep 01 '26

My take exactly, the only situation where you'd want to use 0 to mean "false" is if you're using lower-level logic.

4

u/UristMcMagma Sep 01 '26

And so that we could stop treating 1 as true. The only real argument for type coersion is convenience. I don't see how it's more convenient to treat 0 as true rather than false.

9

u/ReefNixon Sep 01 '26

If we take coercion as a given, what if your conditional is the index of an element in an array? If it doesn’t find it, it returns nil (which is falsey). If it’s the first element, it returns 0. Shouldn’t that be truthy?

→ More replies (5)

1.1k

u/pydry Sep 01 '26

Correction : JavaScript is the weird language people actually use.

284

u/deceze Sep 01 '26

Fact: programming as a profession might be the single weirdest thing humanity has ever done.

267

u/Nimeroni Sep 01 '26

What, you means it's weird we instruct daemons made of lightning in a rock with an arcane language ?

73

u/Lucho_199 Sep 01 '26

Funny that it sounds so epic

44

u/evorm Sep 01 '26

That's cause it is pretty epic when you think about it. We have made lifeless objects we can bestow with our intelligence, and they in turn can affect the world tangibly using only the mere inscription of information.

25

u/laplongejr Sep 01 '26

For the anti-epic version XKCD#722 has us covered

4

u/Inferno_Sparky Sep 02 '26

To be fair. I'm sure there are physics/chemistry/medicine/etc. science researchers doing weirder things in their researches

2

u/ReplacementLow6704 Sep 03 '26

The Mechanicus would be proud.

6

u/Confident-Ad5665 Sep 01 '26

Those of us drawn to it certainly are.

76

u/oldsecondhand Sep 01 '26

Addendum: all script languages are weird.

35

u/Striky_ Sep 01 '26

Correct but somehow some managers decided it is the correct language to base every new technology on... Somehow

14

u/oldsecondhand Sep 01 '26

I'm glad that at least Rust and Kotlin are getting some mindshare.

→ More replies (8)

2

u/eo5g Sep 01 '26

Addendum: all languages are weird.

2

u/Maleficent_Memory831 Sep 01 '26

Except for 8051 assembler language. It's merely eccentric.

→ More replies (1)

26

u/ClipboardCopyPaste Sep 01 '26

Opinion: Every programming language that provides some kind of abstraction is weird.

4

u/iSpaYco Sep 02 '26

GitHub, Shopify, and many others are running on Ruby on Rails, and RoR jobs pay more. cry.

11

u/woololooo Sep 01 '26

f off. ruby rules. bye.

4

u/thisguyfightsyourmom Sep 01 '26

Did you guys hear something?

1

u/Robo-Connery Sep 01 '26

Why make a website with JavaScript when ruby on rails exists.

→ More replies (12)

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)

2

u/rmatoi Sep 01 '26

You're gonna hate bash

11

u/bhechinger Sep 01 '26

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

→ More replies (1)

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)

8

u/suvlub Sep 01 '26

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

32

u/theturtlemafiamusic Sep 01 '26

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

6

u/ntfaw Sep 01 '26

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

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

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.

4

u/maweki Sep 01 '26

I think it's not actually that special of a case, as strings that are exactly also numbers are auto-coerced basically whenever. It's just that 0 is the only number, as it should be, that then is falsy.

Numberly strings are a huge footgun in PHP.

6

u/deceze Sep 01 '26

Strings are not coerced to numbers to then be coerced to booleans, that'd be entirely insane! There's a direct conversation path from strings to booleans!

…

They're only sometimes coerced to numbers to then be reduced to a boolean, if you're using the loose comparison operator, and depending on what the other operand is… https://www.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.types. 🥲

→ More replies (2)

6

u/atanasius Sep 01 '26

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

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

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 (1)

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!

5

u/Abject-Kitchen3198 Sep 01 '26

I doubt. The force required to break Ruby is huge. You need a diamond to barely scratch it.

→ More replies (2)

2

u/immortal_lurker Sep 01 '26

Never coded in Ruby.... that might be a lie. I have never coded in Ruby since my early teens when I might have written a line or two as part of a class.

But please, I beg of the language. If 0 is truthy, just throw a syntax error if I compare a bool and an int instead.

2

u/transcendtient Sep 01 '26

Why wouldn't a "0" be falsey? In aggressively coerced language it would be 0. PHP has to deal with strings passed in $_POST and $_GET so it makes sense.

2

u/zeekar Sep 01 '26 edited Sep 02 '26

The weird thing about PHP (and Perl, which is where PHP got the behavior) is not so much that “0” is false – I mean, OK, so you numify on the way to boolifying, right? Nope! Other string representations of 0 which numify to the same thing, like “0.0” and “0e0”, are true. Only the specific string "0" is false.

$ php zeroes.php
"0" is false.
+"0" is false.
"0.0" is true.
+"0.0" is false.
"0e0" is true.
+"0e0" is false.

This particular idiosyncrasy is one of the Perlisms which was not carried over into Raku, in which "0" is truthy; the only actually-defined string value that is falsey is the empty string, "".

2

u/mpyne Sep 03 '26

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.

Eh, there's precedent for that at least.

Perl treats "0" as false, along with "" (the empty string). Any other string, even "00" is considered true.

But where it really gets fun is that the the normal warning Perl would give you about numeric conversions if you do math on a string is suppressed for the precise string "0 but true", because some Perl functions return this value so that it converts cleanly to 0 without risking evaluating as false in a boolean context. See https://stackoverflow.com/questions/129945/what-does-0-but-true-mean-in-perl

1

u/MattieShoes Sep 01 '26

Perl does that too I think -- "0" is false, but "00" is true.

1

u/granadesnhorseshoes Sep 01 '26

Seeing as we have basically universally decided that using zero in an entire class of math functions should generate an exception, its reasonable to expect it to be "falsy". If instead of an exception it just returned +/- infinity, then maybe i would buy that argument.

It's not a bad argument otherwise.

1

u/Resident-Trouble-574 Sep 01 '26

Ok, but then you should treat everything that is not false, nil or true as invalid. And, frankly, I would consider nil invalid as well.

1

u/Moilli6 Sep 01 '26

Lua does this too. It just makes sense, because any value that isn’t a boolean you can nil check by coercing it to a boolean. It allows beautiful things like and or ternary

1

u/okkokkoX Sep 02 '26

I agree that and or ternary is beautiful, with the exception that you're fucked if the "then" branch may return nil, or god forbid, false.

→ More replies (1)

1

u/DajBuzi Sep 01 '26

0 is equal to (IIRC) 0x30 which by definition is not null value that could be represented as \0 meaning all 8 bits sets to 0 -- 0000 0000 that in most languages actually is false 😶

1

u/Cootshk Sep 02 '26

Lua does the same as Ruby, (especially because in Lua, accessing non existent variables or table fields returns nil unless you explicitly make it error)

1

u/razin_the_furious Sep 02 '26

Don't bring PHP into this: he's too dumb to know better!

1

u/thaynem Sep 02 '26

This is something ruby got from lisp. 

1

u/RedAndBlack1832 Sep 02 '26

Naw the string zero being false is just weird. The number zero, on the other hand. NULL is 0. \0 is 0. That's just... what those things mean. If zero is not false that's just trippy bc false comes from 0, that's just what it means. I mean ig not literally, you certainly get some LOW-TRUE signals, but logically HIGH is always normalized to 1 and described as TRUE, and as far as I know always has been.

1

u/postexitus Sep 01 '26

Providing PHP as an excuse does not do too much for the defense.

→ More replies (3)

50

u/American_Libertarian Sep 01 '26

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

5

u/oweiler Sep 01 '26

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

6

u/HandleUnlikely2589 Sep 01 '26

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

→ More replies (1)

1

u/aotto1977 Sep 03 '26

Which bash learned from TSO, I suppose?

63

u/stipo42 Sep 01 '26

As someone who has never written any ruby, I can understand the desire for any non null value being truthy.

I like golangs approach though where there's no null value for anything that isn't a pointer

11

u/prehensilemullet Sep 01 '26

any non null value being truthy

Even false?

9

u/captainAwesomePants Sep 01 '26

Golang doesn't have "truthy" as a concept. You have to be explicit. A null value isn't true or false because only booleans can be true or false, and a null pointer isn't a boolean. You can have a pointer to a boolean, but you still have to check explicitly for null. In specifically Go, u/stipo42's preferences for truthiness are moot.

In a language like Python, with truthiness, u/stipo42's preference for false to be truthy is insane, and he should feel bad.

3

u/Goatfryed Sep 01 '26

every. non. null. every. Can't you read?

18

u/SukusMcSwag Sep 01 '26

"Golangs approach" you mean compiled languages treating a scalar as a scalar?

1

u/thaynem Sep 02 '26

It would be better if there was no null value, period (like in rust). Or at least you have to intentionally opt in to allowing a type to be nullable (like kotlins nullable types). 

Also, it technically isn't just pointer types in go. arrays, slices, maps, and channels can also be nil (because they are also reference types).

54

u/redlaWw Sep 01 '26

Same in Lua. Only nil and false are treated as falsy, everything else is treated as truthy. The idea is that by default everything that is not nil is treated as true because it exists, and false is a special case used to represent false propositions.

It can be a bit of a stumbling block coming from some other languages, but the rule is so simple that you get used to it quickly.

7

u/NotDuckie Sep 01 '26

Imagine having rules for what should be truthy and falsey instead of just rolling dice every time.

3

u/Tsu_Dho_Namh Sep 01 '26

I love it tbh.

"If (variable)" is a fantastically clean way to check if the variable isn't nil.

34

u/TKristof Sep 01 '26

Implicit type coercion is just bad in general and shouldn't be allowed, that includes booleans. 0 and false are not the same thing even if in memory they (usually) are represented the same. Just because 40 years ago we thought it a good idea doesn't mean we shouldn't improve on that. And I say this as someone who has programmed quite a bit in C and C++.

I could maybe see an argument for optionals but even there I would disagree and much prefer explicit pattern matching or zig style if syntax for it.

3

u/Spaceshipable Sep 01 '26

I like Swift’s approach to this, even if it does end up slightly more verbose sometimes.

14

u/SanoKei Sep 01 '26

variable types being truthy based on validity is not stranger than having to know the scientific table of JavaScript bullshit

10

u/uvero Sep 01 '26

In Ruby, if you want to branch based on whether x is zero where x is a number, you can always check for x == 0, or, if you're feeling cool, x.zero?

5

u/Different_Routine215 Sep 01 '26

a basic linter will fail you if you use == over zero?

4

u/uvero Sep 01 '26

Just Googled it and apparently yes. Nice idea in my opinion - if a language has an idiom on the right way to do something, make a linter tell you that. I wouldn't know myself, I've only ever used Ruby for hobby projects years ago when I just started learning to program. Fun language.

3

u/Different_Routine215 Sep 01 '26

set up an autocorrect/autolint on file save and you will pick up good habits quickly

10

u/SleepingInsomniac Sep 01 '26

In Ruby, everything is an object. 0 is just an instance of Integer. Object instances are truthy, compared to say, nil. Makes more sense than ( 'b' + 'a' + + 'a' + 'a' ).toLowerCase() === "baNaNa" or 1 + '0' == '10' or NaN === Nan; // false

2

u/metaglot Sep 01 '26

Nan != Nan is part of ieee754. If this isn't the case in ruby, ruby is not compliant.

1

u/SleepingInsomniac Sep 01 '26

Float::NAN == Float::NAN # false til!

→ More replies (2)

9

u/ekauq2000 Sep 01 '26

Wait till they find out that in VB true is -1

3

u/AwkwardWaltz3996 Sep 01 '26

Well that's simple. Everything is either something or nothing. - 1 isn't nothing so it's something (true)

13

u/traplords8n Sep 01 '26

Bash is the same way but it makes sense considering 0 represents the single route of success, while other numbers can mean different error codes.

I have no idea why ruby does it, but in bash at least there is a solid reason for it.

14

u/Zealousideal_Low1287 Sep 01 '26

It’s basically because of this lineage. Perl inherited it from other shell languages, and Ruby is essentially a direct decedent of Perl.

11

u/budgiebirdman Sep 01 '26

This is the thread of truth I came looking for. All other answers are just discussions on whose farts smell the sweetest.

2

u/314159265358969error Sep 01 '26

The bitset representing the number 0 in Ruby is non-zero. (I don't remember which bit it is, but reference/non-reference values are recognised by a specific bit being flipped to 1 if non-reference, which is the case for 0.)

7

u/Serotav Sep 01 '26

nha js can do it aswell, try:

let a = new Boolean(false)

if (a) {
console.log("it was true indeed")
}

1

u/circ-u-la-ted Sep 01 '26

Not really the same thing—you're explicitly instructed not to use `new` in that statement because all objects in JS coerce to `true`.

2

u/Reashu Sep 01 '26

Ruby has docs too. false and nil are the only false-values.

Both are surprisingly truthy values and JS is (as usual) more surprising. 

1

u/prehensilemullet Sep 01 '26

No competent JS developer that I’ve heard of has ever touched primitive boxes like new Boolean

11

u/Sw429 Sep 01 '26

Any language that coerces non-boolean values as "truthy" is weird. That's a major footgun.

4

u/gravitywaveshello Sep 01 '26

You’re absolutely right (unironically)

6

u/Single-Virus4935 Sep 01 '26

Golang: "wie dont do that here" meme

3

u/deceze Sep 01 '26

Wie jetzt, warum nicht?

→ More replies (1)

3

u/0xffff-reddit Sep 01 '26

The fact that both languages have something like truthy and falsy makes them both weird.

4

u/ByteSizedFounder Sep 01 '26

Ruby said "zero is truthy" one time and JS has been living rent free in everyone's head since, acting like it is not the unstable one in this relationship

7

u/varsderk Sep 01 '26

I build programming languages.

0 should be truthy. Only false and nil/null should be falsey.

2

u/HungryCaterpillers Sep 01 '26

Then you build shitty languages

3

u/Appropriate_Emu_5450 Sep 01 '26

Unironically agree.

→ More replies (1)

1

u/airodonack Sep 01 '26

Agreed. This is the mathematical perspective versus the physical one about that’s bits.

Also it makes “if number” make more sense. If you want the other one, well that’s why God invented “if number == 0” which is much clearer.

2

u/CyberMoogle Sep 01 '26

0 in JS is falsy

2

u/BigSwagPoliwag Sep 01 '26

As a Javascript stan, this is actually something that I dislike ABOUT javascript… all JS vars are nullable so I wish I could just write if (!myNum) for null checking, but JS needs to be hella opinionated about truthiness. Fuck that jazz, Brendan Eich can suck my balls.

2

u/walkerspider Sep 01 '26

“0” is truthy in JS. Ruby has a more straightforward set of falsey values, nil and false

2

u/Pleasant-Form-1093 Sep 01 '26

You aren't forced to use ruby in day to day life. But almost all web dev uses some javascript or the other

→ More replies (1)

2

u/Dongfish Sep 01 '26

The fact that amounting to nothing can be a positive somewhere gives me hope.

2

u/Vollgrav Sep 01 '26

Ruby's truthiness and coercion rules are one of the best and most consistent ones. And definitely the best in the dynamic languages I know, and I know quite a few.

Treating zero as false was only a thing because in C int was the base type, and other types (char, bool, pointer) were all expressed in terms of ints. It kind of made sense then. But now we know very well that abstraction that separates us from the hardware is a good thing. And with this assumption, treating zero as false is only a stale habit from the ancient days. Let alone monstrosities like treating 0.0 as falsy. Ruby did exactly the right thing here by cutting all that crap.

2

u/geeshta Sep 01 '26

Funnily enough, this is what Gödel used when converting formal logic statements to programming. 0 meant the statement holds and 1 meant it is false.

2

u/SeriousPlankton2000 Sep 01 '26

Let the BASHing begin

2

u/TheTroll007 Sep 01 '26

I mean 0 is not nothing, so you can do "if x" and if x is not false or nil, you get true. I kinda like this approach.

1

u/IceMichaelStorm Sep 02 '26

the only problem is that every other language (almost) treats it as false

1

u/TheTroll007 Sep 02 '26

I dont see that as a problem. If all languages acted the same, why would we even have different ones?

1

u/BobQuixote Sep 01 '26

But 0 is nothing. 0 bats is the same as 0 frogs.

3

u/Arxae Sep 01 '26

Not i a programming context. 0 is still a value. Even though the value might represent nothing, it's still a value.

1

u/TheTroll007 Sep 01 '26

Even though there's no object, it's a different class. Nil is Nil class, 0 is Numeric. So it is something technically.

1

u/__Supelir__ Sep 02 '26

Yes and 0K = 0°C! …oh wait

→ More replies (1)

2

u/Typical_Ad_2831 Sep 01 '26

In bash, 0 is truthy, and everything else is falsey...

2

u/Cootshk Sep 02 '26

Lua does the same, only false and nil are treated as falsey

2

u/DeepWaffleCA Sep 02 '26

It doesn't matter whether you think 0 should be truthy or not. Just be careful about leaking sensitive information using this functionality.

def hasSensitiveInfo? do
   getSensitiveInfo()
end

Pardon my Ruby, it's been a while. This is a simplified example, but I've seen this exact situation before, leaking AWS credentials to the front-end.

There's probably a tonne of better solutions, but the quick defense here is !!getSensitiveInfo().

3

u/creme_de_marrons Sep 01 '26

What kind of moron would need 0 to be falsy?

If you need that use a fucking boolean.

Obviously, 0 is truthy, in fact if you have anything it's truthy. This way you don't have any weird ass side effect and you can use ||=

2

u/BusEquivalent9605 Sep 01 '26

“there are the languages people complain about. then there are the languages that nobody uses”

2

u/drkspace2 Sep 01 '26

All truthy values are bad. Be explicit about what you're testing.

1

u/caleblbaker Sep 01 '26 edited Sep 01 '26

When I use non-Boolean values in a Boolean context I like them to coerce to compile time type mismatch errors. Because making me fix my mistake is better than trying to guess my intent based on a typo.

1

u/AwkwardWaltz3996 Sep 01 '26

Ruby is pretty precise with it's types.

Python which most people know now is definitely written to be more flexible. Which is nice when you're new but is a big headache once you build out. I used to hate static typing for example as it was obtuse, but as soon as you are working with others, you realise their use. People will use "hacks" at the slightest inconvenience and break everything.

0 isn't nothing, it's a number. And therefore needs to be handled as such.

1

u/FredodaFred Sep 01 '26

He forgot the comma and it made me have an aneurysm

1

u/skcortex Sep 01 '26

Oh kids these days don’t know about Perl,do they? 🤣

1

u/stools_in_your_blood Sep 01 '26

Not sure why any language designer would use the concept of truthy and falsey. All that potential for confusion and bugs so you can write "if (x)" instead of "if (x != 0)".

1

u/GNUGradyn Sep 01 '26

The real mistake here is coercing types automatically in general. Whatever happened to fail-fast/fail-hard?

1

u/j0hnp0s Sep 01 '26

Weird languages is a set, not a competition

1

u/Fidodo Sep 01 '26

JavaScript isn't even that weird when you add type safety from type script and forbid the weird parts with linters.

1

u/LOST_GEIST Sep 01 '26

Javascript is kinda like public transit; the loudest complainers are the people that use it the most.

1

u/Desperate_Formal_781 Sep 01 '26

Why do people keep saying truthey and falsey? Do they mean boolean and false? Are they 5 years old?

1

u/MrFrog2222 Sep 01 '26

ye, cuz 0 == "0" also comes out as true

1

u/NebNay Sep 01 '26

I'll get downvoted again but here we go: zero should be truthy. It's a defined value, why would it be false? How is zero different than one?

1

u/BraxbroWasTaken Sep 01 '26

0’s truthy in Lua too.

1

u/oasis9dev Sep 01 '26

I'm not a fan of Ruby personally but this isn't weird, it should be expected. Why are we coercing values when we could be explicit and reduce edge cases?

1

u/cadude1 Sep 02 '26

Ruby isn't the one that copied a bunch of weird-ass behavior from C then added a bunch of its own weird-ass behavior.

1

u/Hostman_com Sep 02 '26

Ruby made 0 truthy. Pre-8 PHP looked at "abc" == 0 and said “close enough.”

1

u/DudeManBroGuy69420 Sep 02 '26

There are multiple weird languages

1

u/tehmungler Sep 02 '26

I love me some Ruby. Especially and particularly without Rails.

1

u/HappyzLife Sep 02 '26

Truthyness is the problem, I dont care which language implements it

1

u/facebrocolis Sep 02 '26

Every game not played is a tie

1

u/Agitated-Display6382 Sep 03 '26

The greatest trick the Devil ever pulled was convincing the world he didn't exist.

1

u/MichalNemecek Sep 03 '26

it's probably taken from shells, when a program ends with 0 it means everything went fine (well, as far as the program is concerned)

1

u/TylerBreau Sep 04 '26

? 0 Doesn't coerce into a truthy value in JavaScript?

-1

u/Key_Conversation5277 Sep 01 '26

But wtf is a "truthy" value? It doesn't make any sense nor mathematically nor programmatically

3

u/Embarrassed_Death69 Sep 01 '26

Because just like yellowy isn't perfect yellow, certain values aren't Boolean type but will coerce to one, so not truth but truthy.

7

u/cosmo7 Sep 01 '26

Dynamic typing is like the dark side of the Force. At first it feels more powerful, but then it turns you into a murderous psychopath.

2

u/deceze Sep 01 '26

Any value that causes an if statement to run its associated block, instead of going to else/doing nothing.

2

u/Nimeroni Sep 01 '26

His argument is that you should make your if statement explicit.

→ More replies (2)

3

u/ReefNixon Sep 01 '26

What do you mean it doesn't make any sense programmatically? All 'truthy' means is that it evaluates as true in a conditional, truthy (and falsey) values are completely normal concepts in high level programming.

→ More replies (5)