r/ProgrammerHumor • u/[deleted] • Feb 05 '19
Rule #2 Violation kill(humans);
https://i.imgur.com/2uY0NW3.jpg6
u/MooseKnuckleJunction Feb 06 '19
Yoda conditionals could have literally saved the programmers' lives
11
5
u/AttackOfTheThumbs Feb 06 '19
I was taught, long ago, that when comparing between some sort of unchangeable value, e.g. a const, to always put it on the left, to avoid this exact issue.
That said, these people deserved it for attempting to write condition == true. == true is redundant as fuck.
3
u/Pvt_Haggard_610 Feb 06 '19
Can someone explain why you would ever want to assign a value inside an if statement condition?
1
1
u/taneth Feb 06 '19
if (isEmpty = length == 0)
It's ugly, but it's valid.
Also, don't do that. Unless it's one of those obfuscated code exercises.
1
u/Hevaesi Feb 06 '19
It's valid only if assignment is an expression.
Some languages leave it as a statement to prevent common bugs that arise with it.
1
1
u/JuvenileEloquent Feb 06 '19
It's not so much that someone wants to assign values inside an if statement, it's that having an assignment be an expression with a value is a useful shortcut in a lot of situations. Since if statements work on expressions, you'd specifically have to ban assignments-as-expressions within if statements in the syntax.
The real problem is that assignment is only one (repeated) character different from comparison. If assignment had to be preceded by a keyword like let or var, it wouldn't be a problem.
2
2
u/hillman_avenger Feb 06 '19
Presumably it's not a const since at some point the spec said "may be required to murder".
1
1
u/Chuck-Marlow Feb 06 '19
I’m more worried that kill and be_nice_to aren’t class methods on humans. Shoddy workmanship
•
u/PatrikxPatrola Feb 06 '19
Your submission has been removed.
Violation of Rule #2: Reposts:
All posts that have been on the first 2 pages of trending posts within the last month, is part of the top of all time, or is part of common posts is considered repost and will be removed on sight.
If you feel that it has been removed in error, please message us so that we may review it.
13
u/taneth Feb 06 '19
Here's a thought. In order to program an AI not to harm humans, you must first program it how to harm humans.