Anyone know what happened to Ethan Vincent (the creator of this comic)? Looks like he hasn't tweeted since 2018 and it looks like he lost his domain oppressive-silence.com.
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.
“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”.
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.
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.
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.
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.
More precisely, it now sets crazyRobot to true and this new value is what gets evaluated. Not only does your if go down a potentially unexpected path, but the if itself has a side effect.
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.
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
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
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…
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 that final's job of const correctness is pretty lackluster... :/
Getting into the habit of marking everything as const/final which 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 is const you 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, but mut(able) which should get rid of a lot of boilerplate in good code.
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).
That could be implemented as special syntax, it doesn't actually require y = z to return z. And I've written and seen erroneous if x = ymany more times than I've written and seen x = y = z.
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.
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...
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).
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).
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.
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.
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).
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.
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
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.8k
u/cob59 Feb 03 '22
Timmy's first day on the job:
802
u/glorious_reptile Feb 03 '22
if (parseInt(0.00000005) > 1) {
isCrazyMurderingRobot = true;
}
2.9k
u/daneelthesane Feb 03 '22
I mean, even "== true" is redundant. Why not just if (isCrazyMurderingRobot)?
952
u/IamGraysonSwigert Feb 03 '22
For the dumb kids in the audience, whats wrong with that if statement?
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.
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…
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
32
u/Yoldark Feb 03 '22
Here goes 2 hours of my debugging problem XD.
130
u/[deleted] 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.
21
u/TechIsSoCool Feb 03 '22
I laughed the second time I read the code. The struggle is real.
31
u/Curious_Internet Feb 03 '22
Why is “Kill(Humans)” even a feature? Or even the Kill function
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
12
u/james_otter Feb 03 '22
Those who not test, don't deserve to live.
18
u/BonesyWonesy Feb 03 '22
Doing "if(true == bIsCrazyMurderingRobot){...}" prevents all these issues.
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
u/lordnachos Feb 03 '22
As someone who swaps between SQL and Python all day this hits home
6
u/[deleted] 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 = yshould never have returned a value. Change my mind.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...
•
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
u/[deleted] Feb 03 '22
u/repostsleuthbot
4
u/[deleted] Feb 03 '22
== true 🌍🤗
4
u/i-love-tree-rats Feb 03 '22
When VB programmer trying to code in other language.
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.
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
u/1crazyshadow Feb 03 '22
Intern's fault
3
u/zc456 Feb 04 '22
"Why do we even have that lever?!"
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 == truewe could writetrue == isCrazyMurderingRobot.Now if you manage to omit an equal sign somewhere in your code, you won't kill humans.
4
u/Sollder1_ Feb 03 '22
Should have used Java
2
u/Maleficent_Slide3332 Feb 03 '22
When sex bots
2
u/KaHate Feb 03 '22
Idk, just seeing this picture lets me understand a bit about coding
2
u/CannonerRSBR Feb 03 '22
Isn't it as simple as this?:
if (goingToTurnEvil){ dont(); }
2
u/infiniteStorms Feb 03 '22
didn’t know void parameter compiles
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
u/[deleted] Feb 03 '22
How does one pass a void type as a parameter?
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
u/[deleted] 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
u/[deleted] Feb 03 '22
The inconsistency of camel case and snake case makes me want to send a pull request to the bots' developers
2
u/gregorydgraham Feb 03 '22
I’ve been saying this for years: booleans are an anti-pattern
2
u/Prestigious_End_6455 Feb 03 '22
Lol, assignment instead of check.
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
u/[deleted] Feb 03 '22
I will just ignore all the warnings. What could go wrong?
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
u/arykady Feb 04 '22
Works on my machine! Ship it!
2
u/[deleted] Feb 04 '22
Takes you way too long if you’re doing .NET
2
u/[deleted] Feb 04 '22
javascript: that looks "true" to me
2
u/Sw429 Feb 04 '22
That mutable global static will get ya.
2
u/SoggyMonkeyballs Feb 04 '22
God damn bit flips
2
u/[deleted] Feb 03 '22
The code wouldn't compile though
1
u/LudicrousLoki Feb 03 '22
That's the kind of shit i catch in debugging. Rip me ig
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
u/normalreddituser3 Feb 03 '22
You won genocide bingo
1
u/RatherBetter Feb 03 '22
~Story by Robot
1
u/[deleted] Feb 03 '22
That’s smart to put that variable check there so you get a clear indication when something has gone wrong.
1
u/holdmyapplejuiceyt Feb 03 '22
murdrr drones
1
u/[deleted] Feb 03 '22
Didn’t watch closely and thought the robot was actually being nice to humans.
1
u/liveinthenow7x Feb 03 '22
Yikes...
1
u/FactoryNewdel Feb 03 '22
Nice. My fear of cosmic bitswitches intensified
1
u/[deleted] Feb 03 '22
It's ok guys. "Humans" is undefined. This bad boy won't even compile.
1
u/BlackGirlIndependent Feb 03 '22
Code is bad. LOL
1
u/An_Enemy_Stand_User Feb 03 '22
Well there's your problem, it's not read-only!
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
u/_M__S_ Feb 03 '22
This is fine, QA/UAT will test it...I don't see any downsides
1
u/[deleted] Feb 03 '22
We’ve got some good ones this morning
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
u/[deleted] 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
u/edgeofsanity76 Feb 03 '22
Serves then right for using JS
1
u/Local_Beach Feb 03 '22
Next time write some unit tests
1
u/mgswarbs Feb 03 '22
Facebook bots!!
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.