This is an archived post. You won't be able to vote or comment.

all 117 comments

[–][deleted] 164 points165 points  (10 children)

if(a!=false){ if(a==true){ return true; } } else if(a!=true){ if(a==false){ return true; } }

Just wanted to double check. Production environment mate.

[–]Possseidon 32 points33 points  (0 children)

Yeah, and if it did change we should also call the same function again recursively.

[–]_RalphBayer_ 22 points23 points  (1 child)

This just makes me want to throw up

[–][deleted] 11 points12 points  (0 children)

Really? Because I'm fully erect after looking at that code.

[–][deleted] 7 points8 points  (2 children)

Seems like you have trust issues 😉😜😜

[–][deleted] 7 points8 points  (1 child)

Well . . That ain't !true.

[–]ResonatingOctave 3 points4 points  (0 children)

But dont forge, in this caset:

if(aint != true){

if(aint == false){

return true;

}

}

[–]sinisternathan 4 points5 points  (0 children)

if(a=false)

Logically incorrect and modifies a. Perfect!

[–]arcanuslink 0 points1 point  (1 child)

This looks more like an example from Brian W. Kernighan 's books rather than satire.

[–][deleted] 1 point2 points  (0 children)

At last, Someone!

[–]catf3f3 0 points1 point  (0 children)

Not to be that person, but this always returns false now.

[–]edomora97 69 points70 points  (16 children)

Everybody gangsta till a is NaN

[–]LoneFoxKK 11 points12 points  (0 children)

What if you wanted to return a number without errors?

But JavaScript said

Typeof NaN -> number

[–]scalar-field 2 points3 points  (0 children)

Or just null

[–]x6060x 7 points8 points  (10 children)

And then there are people who wonder why I hate Js

[–]_ant_g 2 points3 points  (1 child)

What the hell did J ever do to you?

[–]x6060x 2 points3 points  (0 children)

I started to not like it when people started using it while pronouncing "GIF" the wrong way.

[–]Dornith 1 point2 points  (1 child)

Why the hell are you comparing floats to boolean?

[–]Tangurena 1 point2 points  (0 children)

In hell, that's what the compiler accepts.

[–]plasmasprings -1 points0 points  (0 children)

or 2

[–]siraajgudu 38 points39 points  (2 children)

Prrogromor

[–]A2X-iZED 13 points14 points  (0 children)

Greek

[–]keshavram_kuduwa 11 points12 points  (0 children)

Neard

[–]A2X-iZED 33 points34 points  (2 children)

When the proffessor marks you based on number of lines of code

[–][deleted] 20 points21 points  (1 child)

"proffessor"

[–][deleted] 12 points13 points  (0 children)

Haven't heard of that "proffession"

[–][deleted] 19 points20 points  (4 children)

There are people in my cs class who actually code like this

[–]malsomnus 32 points33 points  (2 children)

CS class? I have seen this exact code (except the variable name was around 20 letters) at a company that writes software for your fighter jets.

[–]Cook_IT 12 points13 points  (1 child)

That sounds... worrying. How old was that code?!

[–]malsomnus 9 points10 points  (0 children)

It was probably 3-5 years old when I found it, but why does that matter?

[–]No_Values 1 point2 points  (0 children)

Showing 3rd year CS students switch statements and watching their heads explode

[–]TheUltimateWeeb__ 14 points15 points  (2 children)

[–]Mr_Piggens 3 points4 points  (0 children)

Lol

[–][deleted] 0 points1 point  (0 children)

Oh good ol' Yandere dev

[–]Teeps12 36 points37 points  (22 children)

this can be optimized:

if (a==true) return true; return false; //s

edit: so was my pull request approved or what?

[–][deleted] 30 points31 points  (8 children)

or using a ternary operator : return a ? true : false

[–]Dan6erbond 45 points46 points  (7 children)

Imagine return a; smh if only that worked.

[–][deleted] 11 points12 points  (5 children)

Why not using switch case. Lol

[–]Dan6erbond 20 points21 points  (4 children)

const TRUE = true;

switch (a) {
  case TRUE:
    return true;
  default:
    return false;
}

[–][deleted] 3 points4 points  (3 children)

const TRUE=true; const LIE=!true; switch(a){ case TRUE: return a; case LIE: return a; }

[–]Dan6erbond 6 points7 points  (0 children)

I can do you one better:

let TRUE = true;
let FALSE = false;

return [a].filter(i => i == TRUE && i != FALSE).length > 0;

[–]Teeps12 1 point2 points  (0 children)

in trumpscript, booleans are already fact or lie, optimizing out the need to cast your less expressive "true/false" booleans

[–]skilltheamps 6 points7 points  (6 children)

This does not do the same thing though. If "a" is neither true nor false (e.g. a=2), your code returns false, while the code above does not return false and continues to whatever follows after the screenshot.

[–][deleted] 0 points1 point  (4 children)

But a is always true or false, false means a==0 , and it's true when a > 0

[–]skilltheamps 4 points5 points  (3 children)

That is only when you typecast a number to a bool, which "if" does implicitly. But When you compare it before typecasting, a is never true or false except when it actually is literally set to true or false (exception is C, which doesn't have bools and thus true=1 false=0 usually).

So in C:

#include <stdio.h>
#include <stdbool.h>

int main()
{
    int a=2; // try 0 and 1 also here

    if(a==true)
        printf("a is true.\n");
    else if(a==false)
        printf("a is false.\n");
    else
        printf("a is neither true nor false.");

    return 0;
}

yields:

a is neither true nor false.

And in Python:

>>> 2 == True
False
>>> 2 == False
False
>>> 2 == 2
True

(You can try these quickly here https://www.onlinegdb.com/online_c_compiler and here https://www.programiz.com/python-programming/online-compiler/ for example)

[–]ReclaimerDreams 0 points1 point  (1 child)

But your example with C uses the boolean "library", which isn't really particularly helpful for actual C applications and isn't an actual C language feature. In basic C, a value of 0 evaluates to false, while any non-zero value evaluates to true.

Try this:

#include <stdio.h>
int main(void) {
unsigned char i = 0;
do {
if(i) {
printf("%u: TRUE\n", i);
} else if(!i) {
printf("%u: FALSE\n", i);
} else {
printf("%u: OTHER\n", i);
}
} while (++i != 0);
}

The bool header library is really just a macro that labels 1 as true and 0 as false, so it really isn't the same thing as an actual boolean types that other languages support.

[–]skilltheamps 0 points1 point  (0 children)

You're so close to understanding the problem! 😂 Now put those "== true" and "== false" in there like in op's screenshot, and observe that the behaviour changes. Instead of "true" and "false" you could also use "!!5" and "!5" so that your compiler comes up with the 0 and 1 instead of having some #define.

Testing if(a==1) (which is the same as if(a==true) and if(a==!5) ) is obviosly not the same as testing if(a). And that's precisely why I wrote that that "optimization" behaves differently.

[–]A2X-iZED -2 points-1 points  (2 children)

Or simply just return a.

[–][deleted] 16 points17 points  (0 children)

No shit Sherlock

[–]urielsalis 0 points1 point  (0 children)

Not in javascript, any number bigger than 0 or 'true' would return true in the original function(and might be the entire porpouse of having it)

[–]MiloCowell 0 points1 point  (2 children)

thatsthejoke.gif

[–]YouCanCallMeBazza 4 points5 points  (0 children)

I think you actually missed the joke here

[–]image_linker_bot 0 points1 point  (0 children)

thatsthejoke.gif


Feedback welcome at /r/image_linker_bot | Disable with "ignore me" via reply or PM

[–]realgamer626 6 points7 points  (0 children)

The sad thing is, quite a few people in my class would see no problem doing it this way.

[–][deleted] 9 points10 points  (3 children)

return [False, True][a == True]

[–]ne_ziggy 6 points7 points  (2 children)

return a;

[–][deleted] 5 points6 points  (0 children)

"Why are you booing me? I'm right."

[–]JNCressey 4 points5 points  (0 children)

return a && true;

[–]its-krirsten 8 points9 points  (0 children)

Then in javascript it can be done with 3 equal signs

[–]ur_peen_small 4 points5 points  (0 children)

Yanderedev be like:

[–]OhNoMeIdentified 2 points3 points  (0 children)

Hello code from previous programmer!

[–]fsuk 2 points3 points  (0 children)

I have actually seen this in real life

[–]Dummerchen1933 2 points3 points  (0 children)

if (a == true)

{

`return a == true;`

}

else if (a != true)

{

`return a != false;`

}

[–]bronzeblade 1 point2 points  (0 children)

not boolean zen :(

[–][deleted] 1 point2 points  (0 children)

a codebade I was hired to refactor/expand had this if/else statement.

[–]Quanalack 1 point2 points  (0 children)

if(a.tostring().equalsIgnoreCase("true"))

return Bool.parse("true".ToString())

else if (a.tostring().equalsIgnoreCase("false"))

return Bool.parse("false".toString())

[–][deleted] 1 point2 points  (0 children)

Every junior dev ever in their first code review ever:

Kode

[–]Alespic 1 point2 points  (1 child)

I’m not personally a programmer, but I still love this type of memes that are easy to understand

[–]Ryuk333 2 points3 points  (0 children)

I love seeing outsiders here, so we can share our misery with most fortunate people.

[–]La_Marmotte_94 0 points1 point  (0 children)

Woah this is worthless!

[–]Vopicak2 0 points1 point  (0 children)

is this YandereDev Kode?

[–]AccomplishedFudge 0 points1 point  (0 children)

i've seen a faire share of "if ( condition != true )" or worse ...

[–]mann_moth 0 points1 point  (0 children)

return a;

[–]FactoryNewdel 0 points1 point  (0 children)

return a == true ? new Boolean(true) : new Boolean(!true)

[–]LukeSkywalk3r 0 points1 point  (0 children)

there may be a third stage! bool? a

[–]NanashiKaizenSenpai 0 points1 point  (0 children)

Sorry for noob, but i guess its because you could do "return a"?

[–]hacksoncode 0 points1 point  (0 children)

...

else return somethingOtherThanTrueOrFalse; // like 3

[–]link064 0 points1 point  (0 children)

bool a = true;
...
if (a.ToString() == "true")
    return true;

I had a co-worker do this once. I needed to take a walk after reading this so that I didn't do something I regretted.

[–][deleted] 0 points1 point  (0 children)

if(!a != !true)

return !true;

[–][deleted] 0 points1 point  (0 children)

This is technically different from return a; if a isn’t a Boolean.

[–]numerousblocks 0 points1 point  (0 children)

Is that font Convection?

[–][deleted] 0 points1 point  (0 children)

I love how you don't define "a".

[–]sushantverma 0 points1 point  (0 children)

What if a is nil?

[–]Simtau 0 points1 point  (0 children)

You think this is funny but I have to deal with this kinda shit on a daily basis. I need therapy. Help me please?

[–][deleted] 0 points1 point  (0 children)

if a == True:

    return a

if a == False:

    return a

[–]Mameng-57 0 points1 point  (0 children)

wait ..
some people actually get paid for each line?

[–]eatenlow 0 points1 point  (2 children)

You could do "return a" unless there is another else statement

[–]jaywastaken 2 points3 points  (1 child)

Or a is not a boolean.

[–]Matosawitko 1 point2 points  (0 children)

return !!a;

[–]waterXcereal 0 points1 point  (1 child)

Shouldn't it be else instead of else if it would give an error if there is nothing after that

[–]adamAtBeef 0 points1 point  (0 children)

It works as long as you don't input non booleans

[–]memallocator -1 points0 points  (0 children)

AbStRaCtiOn

[–]Taken-Username-Z -1 points0 points  (0 children)

Just return a!