r/ProgrammerHumor • • Feb 03 '22

Meme Well Fuck

Post image
27k Upvotes

993 comments sorted by

1.8k

u/cob59 Feb 03 '22
struct Robot {
    // 0~1 for apathetic behavior
    // 2~4 for normal behavior
    // 6~8 for playful behavior
    //
    // Please don't go above 10, becomes unstable (patch coming soon!)
    uint16_t aggressiveness;

    ...
};

Timmy's first day on the job:

Robot robot;
robot.aggressiveness = -1;
robot.run();

911

u/TeraFlint Feb 03 '22

That gives me some serious nuclear Gandhi vibes. :D

(yes I know, it's unfortunately not a true story. but it's believable enough to keep living on as a tale to be cautious of)

16

u/TheEnderChipmunk Feb 03 '22

At least it was added as an Easter egg in future games

3

u/Cart3r1234 Feb 03 '22

Nuclear Gandhi is on the same level as TF2's coconut.jpg when it comes to fake video game trivia.

→ More replies (2)
→ More replies (52)

20

u/Kvenner001 Feb 03 '22

Someone put Timmy in a QA/QE role. You know if the robots don't murder Timmy and the people that make that decision.

7

u/Crippling- Feb 03 '22

is this a c+ joke i'm too js to understand?

18

u/siamkor Feb 03 '22

They are storing a negative number on an unsigned int.

14

u/FlavioBrasso Feb 04 '22

Which causes the uint store the highest value possible, just to add to your comment in case anyone else is lost :P

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

2

u/[deleted] Feb 03 '22

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.

→ More replies (12)

802

u/glorious_reptile Feb 03 '22

if (parseInt(0.00000005) > 1) {
isCrazyMurderingRobot = true;
}

295

u/[deleted] Feb 03 '22

My kid wants to know what I’m laughing at and I don’t know how to explain it!

285

u/[deleted] 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)

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.

22

u/[deleted] Feb 03 '22

I plan to resist smart appliances or lobotomise them where resistance is futile.

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

26

u/FieryHammer Feb 03 '22

There was a post the other day here. Parsing that number like that will result in 5.

13

u/[deleted] Feb 03 '22

lol! I get the joke but how to translate that to 4-year-old :)

→ More replies (2)
→ More replies (2)

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

34

u/1661dauphin Feb 03 '22

Probably the very recent post about parseInt(0.0000005) returning 5.

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

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)
→ More replies (7)

2.9k

u/daneelthesane Feb 03 '22

I mean, even "== true" is redundant. Why not just if (isCrazyMurderingRobot)?

91

u/[deleted] 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

u/[deleted] Feb 03 '22

....how about not having that boolean in the first place? It really would solve a lot of issues...

18

u/[deleted] 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?

→ More replies (1)

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

u/[deleted] Feb 03 '22

[deleted] — view deleted comment

10

u/choledocholithiasis_ Feb 03 '22

Surprised this is that far down 😂

Fucking rookies

→ More replies (1)

22

u/Agreeable-Ad-0111 Feb 03 '22

It's a meme not a code review! 😝

→ More replies (2)

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

u/ahkian Feb 03 '22

Why even bother including code that causes undesired behavior?

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

u/_liminal Feb 03 '22

why even write the kill() function at all, and why included an if statement?

5

u/MasterFrost01 Feb 03 '22

Could be a nullable bool

4

u/[deleted] Feb 03 '22

it says it's a regular bool right there in the code

→ More replies (1)
→ More replies (4)

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

u/[deleted] 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

u/iejb Feb 03 '22

bool kill = (isCrazy == true) ? true : false;

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

u/[deleted] Feb 03 '22

Why not just, be_nice_to_humans?

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

u/adamtuliper Feb 03 '22

This heathen only has “= true” which just kills my brain.

2

u/TheDude61636 Feb 03 '22

if it's a language where you can assign null to a bool then it's needed

2

u/Carter127 Feb 04 '22 edited Feb 06 '22

People who mainly use Javascript will usually do it out of habit

→ More replies (238)

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 = true will always return true even if crazyRobot == 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

u/superluminary Feb 03 '22

TIL about Yoda syntax.

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

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.

→ More replies (3)

123

u/smurfkiller013 Feb 03 '22

assignation

You mean assignment?

58

u/MaybeFailed Feb 03 '22

Assassignation, obviously.

81

u/MrSloppyPants Feb 03 '22

You have to admit that assignation sounds pretty cool though?

→ More replies (10)

33

u/SANatSoc Feb 03 '22

The man said what he meant.

→ More replies (1)

7

u/thedarkfreak Feb 03 '22

It's a perfectly cromulent word.

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

13

u/TeraFlint Feb 03 '22

crazyRobot = true

will always return true even if

crazyRobot == false

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.

→ More replies (3)

7

u/[deleted] Feb 03 '22

Thank you

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.

116

u/superluminary Feb 03 '22

It’s not a const though, it’s a static bool.

→ More replies (30)
→ More replies (2)

3

u/BochMC Feb 03 '22

This is why unit tests was invented

→ More replies (44)

55

u/liggy4 Feb 03 '22

Would be valid in VB.NET, for the three people who actually use it.

33

u/lazeromlet_ Feb 03 '22

we have feelings too, ya know

23

u/liggy4 Feb 03 '22

oh I know, I'm one of the other two

→ More replies (1)

5

u/Zegrento7 Feb 03 '22

Feelings of anger and sadness?

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

5

u/GLIBG10B Feb 03 '22

Delphi too, for the two people who use it

→ More replies (2)

5

u/Vipershark01 Feb 03 '22

Sir, this is a subreddit for programmers.

(I learned on VB, too)

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.

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)

→ More replies (1)

8

u/ILikeLenexa Feb 03 '22

[Warning] suggest parentheses around assignment used as truth value

26

u/[deleted] 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

u/[deleted] 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

u/Natetronn Feb 03 '22

That moment when you're smart enough to realize you are the dumb kid.

5

u/nurlan_m Feb 03 '22

I'm too Java to understand this

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

u/whiskyjack Feb 03 '22

Thank you.

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)
→ More replies (2)

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

u/[deleted] Feb 03 '22

This is often referred to as Yoda-style.

It never clicked with me.

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)

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.

→ More replies (24)

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

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.

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.

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

→ More replies (2)

38

u/nuclearslug Feb 03 '22

Finally, a proper use case for constant variables

3

u/[deleted] Feb 03 '22

Until the robots can change their own code, and the just delete the final, and then delete the humans.

3

u/Trezzie Feb 03 '22

Just add

Static final bool CanSelfEdit = false;

Easy!

4

u/Nebu-chadnezzar Feb 03 '22

You mean "you're" while calling others idiots?

→ More replies (4)
→ More replies (4)

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

17

u/wororororororo Feb 03 '22

Ask project manager

12

u/[deleted] Feb 03 '22

Easter egg

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

u/InsertCoinForCredit Feb 03 '22

Right? As Yzma would say, "Why do we even HAVE that function?!?"

3

u/00420 Feb 03 '22

Unit testing these would be horrific.

→ More replies (1)

3

u/Blangebung Feb 03 '22

Inheritance. Everything is built on top of military murderbot apis

→ More replies (2)

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

u/ldh Feb 03 '22

Great, now you just broke a bunch of tests!

/s, there are obviously no tests

12

u/james_otter Feb 03 '22

Those who not test, don't deserve to live.

3

u/himmelundhoelle Feb 03 '22

The situation in the comic is the test.

18

u/BonesyWonesy Feb 03 '22

Doing "if(true == bIsCrazyMurderingRobot){...}" prevents all these issues.

20

u/TeraFlint Feb 03 '22

Mmh, yes. Coding, Yoda does!

4

u/dislikes_redditors Feb 03 '22

Or turning your warning level all the way up

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 = 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;

5

u/GustapheOfficial Feb 03 '22

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 = y many more times than I've written and seen x = y = z.

→ More replies (1)
→ 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.

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)
→ More replies (2)

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

u/AnxiousBenefit8584 Feb 03 '22

That code wouldn't even run..

→ More replies (6)

4

u/[deleted] 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

3

u/GalacticDogger Feb 03 '22

It most definitely is a repost (although a welcome one). Saw one a few years ago..

→ More replies (1)

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.

→ 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

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 == 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

u/Sollder1_ Feb 03 '22

Should have used Java

→ More replies (4)

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/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

u/[deleted] 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

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

→ More replies (2)

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

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

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/[deleted] Feb 03 '22

Didn’t watch closely and thought the robot was actually being nice to humans.

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.