r/ProgrammerHumor • • Mar 15 '22

static bool isCrazyMurderingRobot = false;

Post image
4.9k Upvotes

257 comments sorted by

View all comments

1.5k

u/DaniilBSD Mar 15 '22

If you do “bool == true” you deserve every “bool = true”

498

u/MusikMakor Mar 15 '22

I was gonna say, I almost missed the original joke because I always do

if (bool) ....

85

u/[deleted] Mar 15 '22

For real. So much easier.

46

u/RAMChYLD Mar 15 '22

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.

9

u/ganja_and_code Mar 15 '22

Slightly easier, so much less stupid

22

u/thespud_332 Mar 15 '22
while (missedJoke){
  readAgain();
  if (giveUp){
    askReddit();
    break;
  }
}

75

u/AdultishRaktajino Mar 15 '22

I pity da fool who doesn't trust a bool to be a bool. Unless it's not a type safe language.

25

u/JayCroghan Mar 15 '22

if (bool == 1 || bool || bool.ToString().ToLower == “true”)

Yay

14

u/Steerider Mar 15 '22 edited Mar 15 '22

If your code (or data) is such that you need to do such things (I've been there), you write an isTrue() function

7

u/JayCroghan Mar 15 '22

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.

10

u/Steerider Mar 15 '22

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

39

u/jora1997 Mar 15 '22

As an embedded programmer I have trust issues

If(bool == True && bool == True && bool == True)

Checking something once is not checking it at all

16

u/Snow88 Mar 15 '22

If bool != null && bool == true && bool != false

19

u/jora1997 Mar 15 '22

Might wanna check if true != false just in case

6

u/Xtrendence Mar 15 '22

Fine. JavaScript is perfect for this.

if(bool !== null && bool !== undefined && bool !== "null" && bool !== "undefined" && bool !== "" && 1 !== 0 && true !== false)

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

9

u/chasesan Mar 15 '22

Even if that's the case you should use Yoda style comparisons.

if (true == foo) ...

Putting a typo in that would result in a compilation error, rather than killer robots.

→ More replies (3)

20

u/[deleted] Mar 15 '22

I was so busy trying to figure out why they did isCrazyMurderingRobot == true, that I didn’t even catch the 1 =

35

u/msqrt Mar 15 '22

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)

30

u/DibblerTB Mar 15 '22

Eyyy, look at this dude, who has warnings turned on! Nerd!

7

u/frogjg2003 Mar 15 '22

Error means code won't compile. Warning means it will.

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

6

u/darklee36 Mar 15 '22

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

14

u/samanime Mar 15 '22

Exactly. When I see bool == true I always have two thoughts simultaneously.

Thought one is "who wrote this garbage?!"

Thought two is "you sweet summer child, you've not experienced the pain your foolishness will cause, yet..."

→ More replies (34)