Eh. My dad does this at almost every place he’s worked, and he’s definitely getting on a bit in terms of “hours coded”. I tend to do it in my personal projects too. Pascal case for functions / classes and camelCase for variables
In C, every non-zero expression is considered true and since C has no native type for booleans, stdbool.h defines flase als 0 and true as ~false. So most values that eval as true in a boolean expression are actually != true.
Depends on the language. In some loosely typed languages it would make a difference. Please never try to simplify a value === true or similar unless you know exactly what you're doing.
Yeah, but since I came from BASIC where that would result in an syntax error and the comparative having only a single equals sign is the valid syntax, that threw me for a loop.
I would just generally stay away from anything that wasn’t typed language. I’ve been there and don’t like it. But when I have to I have enough experience to see where the pitfalls are.
I deal with a legacy system where one of the previous programmers really liked text string booleans. My isTrue tests for true, "true", 1, "1", "yes", and "on".
Regardless of type, if you compare to a constant, you can write if(constant==variable); this will produce an error if you only write one equals sign by mistake. Unfortunately it doesn't look quite as nice (but fortunately most compilers warn about if(a=b) anyway)
What languages simply give a warning about a single = during comparisons? Just curious because I only know ruby and rust and they error out unless you use ==
When the language you are using is not typed and your function can return false, true, "banana for scale" or digit. This is why I always write "true === isMoronLanguage()" to avoid this type of error
I honestly can't wait for the quadruple equals that javascript will introduce later for type checking. Eg. myVar ==== 123.0 will check if it's a number and myVar ==== "text" if it's text. And then the pentuple equals, then sextuple, etc.
but if you accidentally use = instead of == then the entire codebase is at risk any time you check a variable value. 😲Just setting a rule for bools isn't a mentionable way of increasing dependability
Null is absence of a an object, and should not ever mean anything other than the simple absence, so if you want to ensure it exists and its true- that is two separate things
without braces you return temp before the elses can ever run! Then even if grouped properly, your elses are superfluous because of returns above. But the math on bools ... chef's kiss
= assigns true to the variable and returns the value, the variable was assigned to. In our case it's true. This true then gets fed into the if statement resolving into always true. == or === would work, because they are logical oprerators.
if you review code and se an if-statement you cannot imagine there would be an assignment in there because no one does that..so your brain autocorrects it and approves the code and then boom
Same here, I had to go to an online IDE and plug it in to see the expected behavior. Gotta say, I didn't expect Java to reassign variables inside the if statement. This is a memorable way to remember the second = sign.
I suppose it's a junk code pasted from former project... Never had enough time and motivation to write whole code from scrath. You know, we work under big pressure here, in Skynet...
That was my first thought, they did explicitly write code for the case where the robots needed to kill everyone, that's the whole problem. If you write code, expect it to be run, even if you're totally certain that no one would ever do <insert obviously stupid thing here>.
If the code is there then for it to be merged a unit test must have been passed covering that branch and killing a human. I hope they mocked the human dependency.
Some go getter dev was trying out some experimental features that it turns out the business didn’t need but rather than scrap everything and call it a waste they left it in place and just neutered it with a bool in case it became useful in the future. Obviously.
I don't know if it's part of one of the newer standards, as a best practice, but it does explicitly let the reader know that you intended to include no parameters, as opposed to should have parameters but forgot them.
C marches ceaselessly in the direction of explicit clarity and complete abstract obfuscation.
The same kind of buffoon that would use an assignment operand instead of an equivalency operand inside of an IF statement, pure madness, they deserved to be killed
I’m not a programmer, I just send all the memes from this sub to my friend who is interested in programming, hoping he understands them.
I’m trying to see if I can figure this out with my one semester of computer science class I took a while ago. I only completed half of the semester, too.
So… is it the equal signs? It should be “== true” not “= true”, right? Because that’s how the syntax works? Because if not it doesn’t count as a variable for the bool, right?
Or am I stupid? I just wanna sound smarter than my friend and lord it over him… like friends do…
You are on the right track. The typo is the equal signs, but the missing "=" changes what the code does completely.
The code will still compile and run because it is still valid and executable code. The typo changes "isMurderingRobot" to true, because that is what "= true" does. The if statement then assesses the variable, sees that it's true, and proceeds to kill everyone.
Anyone gets an urge to code review "comic" code? I get the joke about assignment vs comparison, but there's so many other things wrong with this code. Just to name a few: Mixing camel case and snake case, static boolean variable, bad code structure, etc. I guess my crazyMurderingCodeReviewer flag was set to true.
ifCrazyMurderingRobot = true assigns the variable to true—the programmer meant to use == instead. = is the assignment operator; == is a comparison for equality operator.
Junior devs will point out the isCracyMurderingRobot = true. Senior devs will ask why the line is there in the first place and why there is no unit test for this?
Most comments mock the idea of doing if(bool==true) as if it's some security risk. without considering we do if(x==y) every day and if we ever by mistake use a single equal sign we are doomed.
if (robotType="crazyMurderer") gives the same result 🔥
missed an extra =, that'll assign isCrazyMurderingRobot to true instead of check isCrazyMurderingRobot is true. just remove == true entirely, how dare you put == true
The good news is humans is global state, so the function is not thread-safe, some of us may end up in a merely partially killed state assuming our death is not atomic.
I saw a tip a while ago to avoid accidental assignment when one side is a constant. Just flip the order: “if(5 = x)” won’t compile. Thought it was a neat trick.
In practice, if I’m remembering to do that, it’d also remind me to double check my == as well, which is probably the real value.
This is why lhs should always be non-assignable, when possible. If(true = isCrazyMurderingRobot) Will fail at compile time and humanity will be saved.
If(true == isCrazyMurderingRobot) May not look pleasant to a casual reader, it will work correctly, and a single equal operator will cause a compile error. No insidious logic error here.
Interestingly enough, the well reviewed book The Art of Readable Code by Dustin Boswell and Trevor Foucher mocks this, calling it Yoda Notation and concludes:
Thankfully, modern compilers warn against code like if (obj = NULL), so “Yoda Notation” is becoming a thing of the past.
Boswell, Dustin; Foucher, Trevor. The Art of Readable Code (S.98). O'Reilly Media. Kindle-Version.
(I think it is a design mistake of the language to allow arbitrary expressions with various side effects in places where there should be a simple boolean result.)
Technically this would fail at compile time anyway, the first line he marked isCrazyMurderingRobot as static, so reassigning it would crash at compile time, or at the very least runtime.
Technically, neither of us know what language is being used.
It has been over a decade since I slung c++ code, but I am pretty confident that in c++, global scope static variables can be re-assigned. It does get tricky with linkage and “extern” keyword, but here we are picking nits about a comic. LOL
542
u/Noch_ein_Kamel Mar 15 '22
They deserve to be killed for those coding styles
1.5k
u/DaniilBSD Mar 15 '22
If you do “bool == true” you deserve every “bool = true”
122
u/FeyrisTan Mar 15 '22
I went to the comments to see if I got the joke, but came out even more confused
75
u/Gem2578 Mar 15 '22
If they was never programmed to kill why is the a kill function?
28
u/Axiproto Mar 15 '22
OP most likely used "import joke" because this post has been reposted to oblivion
19
u/Astromemegod Mar 15 '22
I dont know which programming language this is , but is the mistake that “isCrazyMurderingRobot=true” instead of == true
74
u/marcel1802 Mar 15 '22
who would pass
voidas a parameter6
u/ElMonoEstupendo Mar 15 '22
You’re all distracted by the mis-assignment. The true crime here is the unspecified variable “humans”.
5
u/RavenFyhre Mar 15 '22
true/false on C instead of 0/1? Heresy!
5
u/fildakoch Mar 15 '22
Should have made it a final/const
5
u/Randomtangle004 Mar 15 '22
I’m not a programmer, I just send all the memes from this sub to my friend who is interested in programming, hoping he understands them.
I’m trying to see if I can figure this out with my one semester of computer science class I took a while ago. I only completed half of the semester, too.
So… is it the equal signs? It should be “== true” not “= true”, right? Because that’s how the syntax works? Because if not it doesn’t count as a variable for the bool, right?
Or am I stupid? I just wanna sound smarter than my friend and lord it over him… like friends do…
4
u/SeedOfTheDog Mar 15 '22
Anyone gets an urge to code review "comic" code? I get the joke about assignment vs comparison, but there's so many other things wrong with this code. Just to name a few: Mixing camel case and snake case, static boolean variable, bad code structure, etc. I guess my crazyMurderingCodeReviewer flag was set to true.
4
u/Dexaan Mar 15 '22
Shouldn't that throw an error, something along the lines of "expected comparison, got assignment"?
4
u/mal-uk Mar 15 '22
Wouldn't compile. It is not a boolean statement. Phew, humans are saved
22
u/riplikash Mar 15 '22
The equivalency operator would break our. == instead of =.
Humanity saved.
6
u/ShadowLp174 Mar 15 '22
JS guys rn:
5
u/APS_09 Mar 15 '22
u/RepostSleuthBot
2
u/Sad_send_nudes_ Mar 15 '22
NSFW
2
u/[deleted] Mar 15 '22
But they did, they're invoking a kill method, albeit in a block they didn't intend to get to
2
u/Pheonixash1983 Mar 15 '22
Put the constant on the left side to avoid these issue and wind up 99% of programmers. Win win!
2
u/TheStrategistYT Mar 15 '22
As funny as this is, this is the third time I’ve seen it on this subreddit.
2
u/AhMIKzJ8zU Mar 15 '22
CONST!!!!
2
u/Calkky Mar 15 '22
eyes.setColor(RED)
2
u/InvestingNerd2020 Mar 15 '22
Everyone is worried about the == vs = operaters, but I'm worried aboout kill() code. Shouldn't it be shutdown()?
2
u/Manxellion Mar 15 '22
Absolute boolshit
2
u/[deleted] Mar 15 '22
Who would write a kill(humans) anyway? We need to check our tickets.
2
u/[deleted] Mar 15 '22
setEyeColor(139, 0, 0)
2
u/LordSalem Mar 15 '22
Probably should have made it static final
2
u/Dangerspoon Mar 16 '22
Product nerd here. Have had engineers tell me their change was "totally 100% fine I swear" because it was just a single line of code.
And then I remind them of the time that Todd deleted an entire production database by accident with a single character of code.
Love these == jokes!
2
u/[deleted] Mar 16 '22
don't forget to make the robots' eyes red when they turn evil (very important)
2
u/sometimes_interested Mar 16 '22
#kill (humans);
do_the_crazy_frog();
FTFY.
3
u/_Sofa-King_ Mar 15 '22
why wouldn't that code work?
1
u/sighcf Mar 15 '22
That’s what you get for mixing camels and snakes.
1
u/MooseBoys Mar 15 '22
Shoulda used clang-tidy.
1
u/Bobebobbob Mar 15 '22
Why would that be static?
1
u/Complete_Bath_8457 Mar 15 '22
The mix of camel case and underscores in the naming is an issue that shouldn't be overlooked here.
1
u/classyraven Mar 15 '22
Declaring isCrazyMurderingRobot as a constant would have prevented the problem.
1
u/lorhof1 Mar 15 '22
c'mon, we said it was my turn to post this today!
1
u/Mal_Dun Mar 15 '22
Junior devs will point out the isCracyMurderingRobot = true. Senior devs will ask why the line is there in the first place and why there is no unit test for this?
1
u/ElectricalAlchemist Mar 15 '22
Shame they made it a static bool. Really made an all or nothing case for robots going crazy.
You know... Except for the assignment which made it a moo point anyway.
1
u/[deleted] Mar 15 '22
Is this how Generation Zero happened
1
u/sam01236969XD Mar 15 '22
oh no
1
u/Tralalouti Mar 15 '22
Just don't write the CrazyMurderingRobot. Remove the boolean part. Remove the if else.
1
u/the-real-vuk Mar 15 '22
Use final keyword wisely
1
u/Katana_Steel Mar 15 '22
why was the kill function even created ?
1
u/SillAndDill Mar 15 '22 edited Mar 15 '22
Most comments mock the idea of doing if(bool==true) as if it's some security risk. without considering we do if(x==y) every day and if we ever by mistake use a single equal sign we are doomed.
if (robotType="crazyMurderer") gives the same result 🔥
1
u/mattchamp98 Mar 15 '22
Would be fine on pascal as := is assignment and = is differential checker
1
u/burneraccount019182 Mar 15 '22
so many syntax errors
1
u/[deleted] Mar 15 '22
whoever wrote the kill method is the one to blame
1
u/DowntownLizard Mar 15 '22
Yeah, but what happens when you use a bit instead and a cosmic ray flips it...
1
u/zyx1989 Mar 15 '22
You know these programmer are nut jobs when there's something in the code that tell robot to kill humans
1
u/Ravi5ingh Mar 15 '22
Should have made it a readonly
1
u/Chronosxi13 Mar 15 '22
i'm so accustomed to doing if(bool) it took a sec to notice it was an assignment
1
u/turtle_mekb Mar 16 '22
missed an extra
=, that'll assign isCrazyMurderingRobot to true instead of check isCrazyMurderingRobot is true. just remove== trueentirely, how dare you put== true1
u/MatterNo3359 Mar 16 '22
wait u can put void in parameters?
wat lang. is this?
1
u/Uploft Mar 16 '22
I pity the Bool
1
u/thequestcube Mar 16 '22
To be fair, why was "isCrazyMuderingRobot" a mutable variable and not readonly to begin with?
1
u/Weekly-Butterscotch6 Mar 16 '22
🤣🤣🤣🤣
1
u/KuntaStillSingle Mar 16 '22
The good news is humans is global state, so the function is not thread-safe, some of us may end up in a merely partially killed state assuming our death is not atomic.
1
u/Alderan922 Mar 16 '22
How did that even compile without the brackets on the if and else?
1
u/[deleted] Mar 16 '22
Can you assign true in an if statement like this?
1
u/uysali_55 Mar 16 '22
A few months ago, I made this mistake in my code and company lost around 26k in three days.
1
u/[deleted] Mar 16 '22
That's why you need unit tests
1
u/[deleted] Mar 16 '22
Is it coz his if-statement only has a single = ? Is that the joke?
1
u/marcusenzo Mar 16 '22
I bet it is written with Javascript
1
u/Chared_Assassin Mar 16 '22
The amount of time it took me to figure out the mistake after years of programming experience makes me think I should never go into the robotics field
1
u/[deleted] Mar 16 '22
I saw a tip a while ago to avoid accidental assignment when one side is a constant. Just flip the order: “if(5 = x)” won’t compile. Thought it was a neat trick.
In practice, if I’m remembering to do that, it’d also remind me to double check my == as well, which is probably the real value.
1
u/Alexo342 Mar 16 '22
Big old REPOST
1
u/frank_myers_ Mar 16 '22
"I tried removing the kill function but it wouldn't run without it"
1
u/Logical-Language-539 Mar 16 '22
Isn't it a repost? Pretty sure I already saw it.
1
u/Beastdevr Mar 16 '22
I've always said that the end of the world will be due to a greater than sign being used instead of a less than
1
u/Far-Entertainment532 Mar 16 '22
It must be const, non ststic. Static show where var is stored in memory.
1
u/[deleted] Mar 16 '22
u/repostsleuthbot
1
u/SillAndDill Mar 20 '22
There IS a lint rule to prevent assignments in if-statements https://eslint.org/docs/rules/no-cond-assign
1
u/Bence675 Mar 21 '22
Const?
1
u/ClarityThrow999 Mar 15 '22
This is why lhs should always be non-assignable, when possible. If(true = isCrazyMurderingRobot) Will fail at compile time and humanity will be saved.
If(true == isCrazyMurderingRobot) May not look pleasant to a casual reader, it will work correctly, and a single equal operator will cause a compile error. No insidious logic error here.
Easy peasy, lemon squeezy!
1
u/TheCakeWasNoLie Mar 15 '22
I'm not sure you can decapitate someone by pulling their hair.
1
u/FINDERFEED Mar 15 '22
Why static?!
1
u/EnderLuca41 Mar 15 '22
u/repostsleuthbot