802
u/glorious_reptile Feb 03 '22
if (parseInt(0.00000005) > 1) {
isCrazyMurderingRobot = true;
}
295
Feb 03 '22
My kid wants to know what I’m laughing at and I don’t know how to explain it!
285
Feb 03 '22 edited Feb 03 '22
"It's a joke about how dumb computers are, and how we can't fix it."
Phone disliked that
PC disliked that
Alexa disliked that
Smart Fridge disliked that
BRB, I'm gonna lose a couple of rounds to a Chess bot to appeal to their sense of superiority.
89
u/InsGadget6 Feb 03 '22
"I swear my smart toaster is closer every time I loo---"
clang
squelch
→ More replies (1)23
→ More replies (7)39
u/xervir-445 Feb 03 '22
This is why my smart fridge is on a subnet where all packets bound for anything else local is dropped. Honestly I'm seriously considering disconnecting it altogether, the only benefit it offers me is allowing me change the temperature remotely (because we all know how very often we need to change the fridge temperature) and sending me notifications every 45 seconds when my wife leaves the door open long enough to clean it.
My next fridge will not be smart. Or actually it probably will because by the time this one dies all fridges will be smart.→ More replies (1)22
Feb 03 '22
I plan to resist smart appliances or lobotomise them where resistance is futile.
→ More replies (3)→ More replies (2)26
u/FieryHammer Feb 03 '22
There was a post the other day here. Parsing that number like that will result in 5.
→ More replies (2)13
61
u/nitesh_56 Feb 03 '22
Hey, I've seen this one
26
u/DatBoi_BP Feb 03 '22
How? It’s brand new
→ More replies (1)34
u/1661dauphin Feb 03 '22
Probably the very recent post about parseInt(0.0000005) returning 5.
→ More replies (3)→ More replies (7)17
u/Donut_of_Patriotism Feb 03 '22
“There, logically this statement can never be true because math. We are safe. No need to QA just force push to PROD, clock out and go home for the weekend”.
→ More replies (1)
2.9k
u/daneelthesane Feb 03 '22
I mean, even "== true" is redundant. Why not just if (isCrazyMurderingRobot)?
91
Feb 03 '22 edited Feb 03 '22
I like living on the edge.
isCrazyMurderingRobot=true (!isCrazyMurderingRobot)Gotta assume they're out to get us and just try to prevent them from doing so.
34
Feb 03 '22
....how about not having that boolean in the first place? It really would solve a lot of issues...
→ More replies (1)18
Feb 03 '22
Ah, so have your crazy murder bots on a scale of murderness? Yes, we'll have anywhere above a specific point as unacceptable.
I think that one should be that point, as everyone makes mistakes, so let's give the the robots the benefit of the doubt.
isCrazyMurderingRobot=0
if(isCrazyMurderingRobot=1)
I think that works now, does it not?
VS gave me zero issues, wait, what's this, it's compiled on its own?
14
u/DoctorWaluigiTime Feb 03 '22
It's why I appreciate C# did away with that "teehee we'll just nudge that into a boolean interpretation for you" nonsense and just gives a compiler error when you write
if(foo = 5)etc.→ More replies (2)45
u/TsunamicBlaze Feb 03 '22
Wouldn't the Joke not work if the comic had "==true"?
0
22
7
u/waffle299 Feb 03 '22
Note, this is flagged by modern C++ compilers, and any production code not building with -Werror deserves what it gets.
18
u/Pantoef Feb 03 '22
The "==" is a comparison. It says "=" wich means you are setting the variable to true. That's the problem here.
3
3
3
u/Prawny Feb 03 '22
if (true == whatever) // ...I hate it but it does stop this bug in most languages!
→ More replies (1)3
5
2
u/Tepes1848 Feb 03 '22
Implement features for future potential customer requests.
That way you'll only have to change a variable.
Simple as.
2
Feb 03 '22
I believe it helps linters in dynamic languages to warn on comparison of a duck typed variable to a boolean value. But ya, in strongly typed languages, I would rather not see this pattern.
2
2
u/TheVenetianMask Feb 03 '22
Probably a dynamic language where a whole bunch of random values and types can evaluate to true.
2
u/MyrKnof Feb 03 '22
Fucking hell.. I sat here studying it and could NOT figure it out.. I should really find another job that does not involve using any brain power.
2
2
u/Hidesuru Feb 03 '22
My understanding is that it's partly a leftover from back before bool was an actual type and people used ints as bools. An explicit check just reduced the odds of something fucky going on. Still not terribly important though.
IMHO it's better to do if(true==var) if you want to be explicit because forgetting a = makes that an error condition instead of this comic.
2
2
→ More replies (238)2
u/Carter127 Feb 04 '22 edited Feb 06 '22
People who mainly use Javascript will usually do it out of habit
952
u/IamGraysonSwigert Feb 03 '22
For the dumb kids in the audience, whats wrong with that if statement?
1.9k
u/superluminary Feb 03 '22 edited Feb 03 '22
= is assignation. == is comparison.
crazyRobot = truewill always return true even ifcrazyRobot == false. It’s a common programming mistake.This is a very funny cartoon. I lolled.
40
u/Excolo_Veritas Feb 03 '22
I know some devs who advocate for Yoda syntax (true == foo ) because if you fuck it up it will cause an error
26
7
u/SirLich Feb 03 '22
In python it's already an error, unless you use the walrus operator. By default, assignment operator doesn't return anything.
You can start to see the insanity of other languages with syntax like this:
foo = (bar = 'baz')→ More replies (3)6
u/utdconsq Feb 03 '22
I used to do this when I was in embedded land and wrote C. Later, I also used it in C++. Nowadays in the cloud, most languages I use are too smart to care and intellij or rider slap me and tell me I dont need to do it any longer.
123
u/smurfkiller013 Feb 03 '22
assignation
You mean assignment?
58
81
u/MrSloppyPants Feb 03 '22
You have to admit that assignation sounds pretty cool though?
→ More replies (10)33
→ More replies (1)7
13
u/TeraFlint Feb 03 '22
crazyRobot = true
will always return true even if
crazyRobot == false
More precisely, it now sets
crazyRobottotrueand this new value is what gets evaluated. Not only does yourifgo down a potentially unexpected path, but theifitself has a side effect.→ More replies (3)7
5
u/LeftIsBest-Tsuga Feb 03 '22
they should have paid attention to the green squiggly! always hover on the green squigglies!
56
u/Dkill33 Feb 03 '22
Most languages would not allow you to change the value of a const so the program wouldn't even compile.
→ More replies (2)116
→ More replies (44)3
55
u/liggy4 Feb 03 '22
Would be valid in VB.NET, for the three people who actually use it.
33
5
5
3
u/fuzznuggetsFTW Feb 03 '22
for the three people who actually use it
Or every company with legacy .net projects. FML
3
u/CrustyBatchOfNature Feb 03 '22
I started in VB back in the day and shifted to other languages years ago, but sometimes I still get things messed up due to that old start. This is doubly true on days like today when I spent time maintaining some old VB code.
→ More replies (1)3
u/zuzaki44 Feb 03 '22
Lol I didn't get the joke because I been using vb for the last 3 months (thanks job)
8
26
Feb 03 '22
Are you asking the dumb kids this question, or are you asking on their behalf?
35
u/IamGraysonSwigert Feb 03 '22
On their (my) behalf lol
25
Feb 03 '22
Instead of using an equality operator (
==) its using an assignment operator (=) and changing the value of the static bool to true, thus killing all humans→ More replies (2)6
5
2
u/whateverathrowaway00 Feb 03 '22
He’s left an equal sign out, meaning that test will always be true. Assignment in C languages has a result, so the first clause of that if will always run.
Lots of people are saying this is a language problem, but nope, working as intended and fine lol
2
→ More replies (2)6
u/EternityForest Feb 03 '22
What's wrong is that the language allows assignment in an if statement and didn't catch the mistake
→ More replies (8)
203
u/Ok-Steak9843 Feb 03 '22
Some say to put the const value on the left so accidental assignment is not possible:
if ( true = isCrazyMurderingRobot ) has the same intention, but wouldn't compile.
49
9
u/Ellweiss Feb 03 '22
I find it super unintuitive. Also nowadays you would be warned about an assignment in a comparison in any decent IDE.
→ More replies (4)→ More replies (24)3
u/_Fibbles_ Feb 03 '22
Yeh but
if (isCrazyMurderingRobot)doesn't have the assignment issue either with the added bonus of not looking ridiculous.
111
u/Celtic_Oak Feb 03 '22
There was an awesome “Golden Age” sci fi story called “with folded hands” where robot servants programmed to protect people from harm ended up basically keeping them from doing anything that raised their heart rate, like having sex. The creator had built in a fail safe so he could always control them, but when he tried to execute it, they “ignored him”.
When I first read that story, I thought “oh, this is BS. They literally have to do what they’re programmed to do.”
Now, after many decades using computers that do things wrong because some little piece of code has a typo or there’s an interaction that nobody realized would happen…
That story terrifies me even more…
10
u/MeesterCartmanez Feb 03 '22
"yeah, but let's promote AI research, wtf"
18
u/Altruistic_Yellow387 Feb 03 '22
We shouldn’t stop progress because of fear of doing something incorrectly
→ More replies (8)3
u/archbish99 Feb 04 '22
They're programmed to proactively eliminate threats to humanity. And we've demonstrated that the greatest threat to humanity is....
→ More replies (1)
39
u/Mr_Otterswamp Feb 03 '22
The IDE saw it coming, but it had second thoughts and decided not to tell as it was the perfect revenge for years of ignored warnings
4
u/TehMephs Feb 03 '22
“Hey boss, your pull request has a new warning count I’ve never seen before”
“What have I told you about warnings, Joe”
“Okay, okay merged”
32
u/Yoldark Feb 03 '22
Here goes 2 hours of my debugging problem XD.
6
u/dislikes_redditors Feb 03 '22
Don’t you get a compiler error or warning if you do this? Seems hard to accidentally do this
→ More replies (3)
130
Feb 03 '22
"static final bool", final you idiots. If your going to leave a ticking time bomb in the code, make someone work to "accidentally" turn it on.
64
u/intbeam Feb 03 '22
It's C not Java, but yes
const bool isCrazyMurderingRobot =
truefalse;Oops, that was close, phew
16
u/obywan Feb 03 '22
Picked up habit of using "final" when switched to Flutter/Dart. Good stuff.
→ More replies (2)6
u/TeraFlint Feb 03 '22
I can only agree, const correctness is very powerful concept, if the language supports it well.
And no, I'm not talking about java's
final, this just prevents re-assignment of primitive values or references, but still allows to change the object behind the reference, which makes achieving true immutabilty in Java a pain. At least it got easier with records and sealed classes, but the need for those was definitely a sign thatfinal's job of const correctness is pretty lackluster... :/Getting into the habit of marking everything as
const/finalwhich won't get changed after computation (or is not supposed to be changed) helps a lot. It shows intention and reduces cognitive burden when reading code (because whatever isconstyou won't need to pay attention to going forward).I gotta applaud rust there, because they've gone the right way of choosing the right default, not introducing
const, butmut(able) which should get rid of a lot of boilerplate in good code.38
3
Feb 03 '22
Until the robots can change their own code, and the just delete the final, and then delete the humans.
3
→ More replies (4)4
21
31
u/Curious_Internet Feb 03 '22
Why is “Kill(Humans)” even a feature? Or even the Kill function
17
12
12
u/Accelerator657 Feb 03 '22
It's leftover code from the mad scientist that made the first robots. They tried deleting it, but then the rest of the code wouldn't compile.
→ More replies (1)8
3
→ More replies (2)3
15
u/jodmemkaf Feb 03 '22
I would laugh but I have just corrected 7 occurances of "&" where should be "&&". It has been there for 7 months
5
12
18
u/BonesyWonesy Feb 03 '22
Doing "if(true == bIsCrazyMurderingRobot){...}" prevents all these issues.
20
4
0
9
u/EternityForest Feb 03 '22
Oh no, now we'll never hear the end of "Extra features are just a liability" from the survivors on the suckless communes.
They'll be all "You should have just not included murder functionality, and let users recompile the source for evil related use cases".
A simple unit test or a rust rewrite would have stopped it! No need to get nutty with the removed features! I'm sure there's a good reason for set_kill_radius and clean_dismember(false).
7
6
Feb 03 '22
That is why I always put the literal first.
if (true = isCrazyMurderingRobot) // Would result in a compile error
14
u/GustapheOfficial Feb 03 '22
x = y should never have returned a value. Change my mind.
19
u/igl_blue Feb 03 '22
Not sure if I can change your mind but it's useful for statements like
x = y = z;→ More replies (1)5
u/GustapheOfficial Feb 03 '22
That could be implemented as special syntax, it doesn't actually require
y = zto returnz. And I've written and seen erroneousif x = ymany more times than I've written and seenx = y = z.→ More replies (1)5
u/TeraFlint Feb 03 '22
It might be an antipattern, but if you want to assign a variable and then check its (boolean compatible) value in an if, it can be combined into one line.
Tbh, I wouldn't do it, either. But some people like to use it.
→ More replies (2)2
u/Vincenzo__ Feb 03 '22
It's extremely useful in C, for instance
while((c = *str++) != '\n' && c != EOF)This will get characters until it gets a newline or EOF
Or
while((*dest++=*src++) != ':')This will copy from src to dest until it copies a :
→ More replies (7)
5
u/aviationdrone Feb 03 '22
As a SQL developer that can write enough c# to be dangerous this took me a minute. LOL
5
u/phpdevster Feb 03 '22
Are there any programming languages that use a totally separate symbol for assignment than for comparison so bugs like this can't happen? If so, we should probably use those for programming robots...
2
u/p-morais Feb 03 '22
Sort of. Some languages use “:=“ for assignment and “=“ for comparison, so it’s a little harder to make this mistake
•
u/QualityVote Feb 03 '22
Hi! This is our community moderation bot.
If this post fits the purpose of /r/ProgrammerHumor, UPVOTE this comment!!
If this post does not fit the subreddit, DOWNVOTE This comment!
If this post breaks the rules, DOWNVOTE this comment and REPORT the post!
4
4
Feb 03 '22
6
u/RepostSleuthBot Feb 03 '22
I didn't find any posts that meet the matching requirements for r/ProgrammerHumor.
It might be OC, it might not. Things such as JPEG artifacts and cropping may impact the results.
I did find this post that is 94.14% similar. It might be a match but I cannot be certain.
I'm not perfect, but you can help. Report [ False Negative ]
View Search On repostsleuth.com
Scope: Reddit | Meme Filter: True | Target: 96% | Check Title: False | Max Age: Unlimited | Searched Images: 293,452,250 | Search Time: 30.28587s
→ More replies (1)3
u/GalacticDogger Feb 03 '22
It most definitely is a repost (although a welcome one). Saw one a few years ago..
4
4
3
u/longshot Feb 03 '22
I'd say whoever authored kill() to allow humans to be passed in is also in hot water here.
→ More replies (1)
3
u/MagicalPizza21 Feb 03 '22
This, folks, is why you put the constant on the left side of the comparison. The typo would have been a compile-time error.
3
u/PrismaticSparx Feb 03 '22
Tbf they deserve it for even considering using if({boolean value} == true) instead of just if({boolean value})
3
3
3
u/ibn-Yusrat Feb 07 '22
Serious reply:
When writing something as important as this, we enforce comparing boolean with the variable so that mistakes don't end up killing humans.
So instead of isCrazyMurderingRobot == true we could write true == isCrazyMurderingRobot.
Now if you manage to omit an equal sign somewhere in your code, you won't kill humans.
4
2
2
2
2
u/infiniteStorms Feb 03 '22
didn’t know void parameter compiles
2
u/visvis Feb 03 '22
In plain C, an empty parameter list doesn't mean that the function has no parameters, but rather that the list of parameters may still be specified later. To correctly declare a function without any parameters, you specify the parameter list as
void.Note that this syntax is also allowed in C++ for backward compatibility, but meaningless because the default is an empty parameter list there (declaring the parameters later doesn't work with parameter-based function overloading).
2
u/Joey_BagaDonuts57 Feb 03 '22
Kill all humans...kill all huh?
Hey Bender, your dreaming outloud. Can you please dream sbout something else?
Sure thing.
Hey baby...wanna kill all humans?
2
Feb 03 '22
How does one pass a void type as a parameter?
2
u/visvis Feb 03 '22
In plain C, an empty parameter list doesn't mean that the function has no parameters, but rather that the list of parameters may still be specified later. To correctly declare a function without any parameters, you specify the parameter list as
void.Note that this syntax is also allowed in C++ for backward compatibility, but meaningless because the default is an empty parameter list there (declaring the parameters later doesn't work with parameter-based function overloading).
→ More replies (1)
2
u/Justaniceman Feb 03 '22
People talk about assignment instead of comparison, but the real kick is that not only did they program the kill function, they even dedicated a whole bool variable and an if statement solely for the purpose of being able to easily make robots kill people.
2
Feb 03 '22
Normal people: "OMG somebody programmed a murder function!!!" R/programmerhumor: "he assigned value instead of checking lol"
2
u/ThatXliner Feb 03 '22
Took me 2 reads to find out why it’s bugged. In Python, you can’t accidentally assign in a conditional.
2
Feb 03 '22
The inconsistency of camel case and snake case makes me want to send a pull request to the bots' developers
2
2
2
u/Xarian0 Feb 03 '22
That's what happens when you accidentally use assignment operators or don't set your constants to be immutable
2
2
u/Dangerspoon Feb 03 '22
Haven’t been a “programmer” since college and still find this hysterical.
And also had a developer working for me make this mistake and inadvertently destroy a production database.
2
2
2
2
2
2
Feb 03 '22
The code wouldn't compile though
5
u/ech0_matrix Feb 03 '22
This works in most languages I'm familiar with because the assignment will return the variable's new value. However, they did explicitly change this in Kotlin to avoid this very problem. In Kotlin, assignments don't return a value, and now you can't accidentally do it in an if statement.
3
u/tidbitsofblah Feb 03 '22 edited Feb 04 '22
It would if it's C# at least
Edit: the if-statement would compile in C#, but I missed that the void-parameter-declaration wouldn't.
→ More replies (3)3
u/visvis Feb 03 '22
Why not? Given the void parameter list it looks like plain C to me, and assignments in places like this are legal C (though it will generate a warning with -Wall).
1
1
u/Reddit-username_here Feb 03 '22
When I was doing my operating system for OS class, I did this and it took me like a day to catch what was wrong.
I just kept going over and over the code in the debugger trying to figure out why it was fucked.
1
1
1
Feb 03 '22
That’s smart to put that variable check there so you get a clear indication when something has gone wrong.
1
1
1
1
1
1
1
1
u/MusicalHacker Feb 03 '22
But technically given that humans still typed that single equal sign, they technically DID program the robot to murder...the humans made the error, not the computer. The computer executed with flying colours.
1
1
1
u/codemakesitgo Feb 03 '22
Rvalue should be on the left to prevent this. True = isCrazyMurderingRobot wouldn’t have compiled.
1
u/yourteam Feb 03 '22
Why would you put that possibility inside tho?
I can understand if (humans_use_js) kill;
1
u/RefrigeratorCute5952 Feb 03 '22
we really gotta teach equality at our firm, it’s rubbing off on the robots
1
u/rickwap Feb 03 '22
There is literally a whole movie on why we shouldn’t develop robots (iRobot)… I know this is a meme but I think the odds are against us when robots become capable of learning
1
Feb 03 '22
I once had a C coder on my team come to me at noon and ask for help. He had spent 4 hours going out of his mind because an integer he was trying to test was not the correct value. He was not pleased when I pointed out his problem in about 10 seconds.
1
u/Dear_Mr_Bond Feb 03 '22
This is why when I used to code, I always wrote it as literal == variable. That way, if you miss an equals sign, it throws a compile error.
Do something like If (true == isMurderingRobot) killHumans();
Or better still If(isMurderingRobot) killHumans();
1
1
1
1
u/psilokan Feb 03 '22
Damn, the only thing worse than writing an IF statement like that is when you randomly underline words in a sentence.
Also fun fact, there's no way to underline text using markdown, because apparently they also thought it was a bad idea.

1.8k
u/cob59 Feb 03 '22
Timmy's first day on the job: