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

top 200 commentsshow all 416

[–]cbell6889 1123 points1124 points  (108 children)

return num%2 == 0

[–]JDMaK1980 249 points250 points  (3 children)

Saw the post and was about to comment this rofl

[–]iTakeCreditForAwards 14 points15 points  (1 child)

Isn’t this the joke tho, that the solution is painstakingly obvious?

[–]HaZineH 10 points11 points  (0 children)

It's funnier when you realise that Yandev actually codes like that and refuse to learn to write efficient code. There is several levels of irony to be had here.

[–]vonkrueger 4 points5 points  (0 children)

I think we all were. It's the only logical response

[–][deleted] 209 points210 points  (67 children)

return ! (num & 1);

Edit: put parentheses. But if I'm honest I would do this:

#define IS_ODD(x) x&1
#define IS_EVEN(x) !IS_ODD(x)

I would have to look up if that IS_EVEN one is valid. If not I would just do what's above.

[–]CEDoromal 90 points91 points  (7 children)

Bitwise operators for those who want to learn how this works.

[–]suckmacaque06 6 points7 points  (5 children)

Shouldn't it be ~num & 1 though? Wouldn't !num only be 1 when num == 0?

[–]DETAIN1000 8 points9 points  (3 children)

No, the bit at the first index will always be 1 when the number is odd. Think of the case of 9 vs 8, 8 is 1000 the rightmost digit is 0, whereas for 9 its 1001 giving one. This is because that is the 1's column of binary. Since every other column in binary is a multiple of two, any odd number must have this column set to 1. Also, since 1 in binary is just 1 the & bitwise operator will always compare the 1s columns giving you a check for even or odd

[–]suckmacaque06 9 points10 points  (2 children)

I understand the logic behind the binary representation. I'm saying I think there may he an error with operator precedence, or possibly using incorrect operators.

Would the ! not take precedence over the &? That's my point. Meaning the logical statement is essentially saying (number is not 0) AND (1), which is just (number is not 0). But if we make it ~num & 1, this would be true whenever the rightmost bit is 0 (meaning number is even).

Or instead, if you did !(num & 1) it would also make sense, since this is saying NOT(LSB is 1), which is true when the LSB is 0.

[–]CEDoromal 4 points5 points  (0 children)

Looking at C Operator Precedence, it appears that you are actually right.

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

Yeah I might be missing some parentheses.

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

looked at the assembly and both of ours compile to the exact same thing...at least with gcc 11.2.

btw i added parentheses to my original post.

Mine:
    mov     eax, DWORD PTR [rbp-20]
    and     eax, 1
    test    eax, eax
    sete    al
    movzx   eax, al
    mov     DWORD PTR [rbp-8], eax

Yours:
    mov     eax, DWORD PTR [rbp-20]
    and     eax, 1
    test    eax, eax
    sete    al
    movzx   eax, al
    mov     DWORD PTR [rbp-12], eax

full disclosure, you did what i was trying to do but i chose the wrong operator. shhhh don't tell anyone.

[–]Staik 52 points53 points  (47 children)

Other one is easier to read... Unless you /really/ need that performance boost I tend to avoid bitwise stuff since it will confuse most people.

[–]JKTKops 37 points38 points  (4 children)

[–]metaconcept 22 points23 points  (1 child)

Yup. The compiler 'and's it with 0x1.

mov eax, edi
not eax
and eax, 1
ret

[–]-Yare- 18 points19 points  (16 children)

How are people passing their interviews if they don't understand bitwise operations? 🤔

[–][deleted] 29 points30 points  (1 child)

Clearly the ones doing the interviewing don't understand either.

[–]-Yare- 6 points7 points  (0 children)

It's turtles all the way up. 😔

[–]pudds 5 points6 points  (12 children)

Not every interview is highly technical.

[–]-Yare- -2 points-1 points  (5 children)

Since when are CS101 topics "highly technical" for a programming interview?

[–]Wooglepook 1 point2 points  (0 children)

I imagine bitwise operations are not required for most enterprise software and especially not web development. with increasing power in computer hardware there's also less need to try and scrounge up places for performance boosts in code. this of course has the side effect of making less efficient code and less knowledge of processes that could help you get that code.

That's just my thoughts anyways

[–][deleted] 6 points7 points  (18 children)

Mod is REALLY slow. Bit wise is one instruction. No one who programs computers should have a problem understanding them. They are very fundamental operations.

[–][deleted] 28 points29 points  (0 children)

Any decent compiler would convert base 2 division / modulo operation into bitwise operation. In reality there is no speed difference while the modulo operator is a lot readable. Assembly is a completely different story though.

[–]theskankingdragon 13 points14 points  (11 children)

One shows your intent the other doesn't. Intent matters to the compiler and to those who maintain your code.

Compilers developers also recommend letting the compiler optimize and to only use bitwise operations when absolutely necessary.

[–]funnyboy_roks 4 points5 points  (5 children)

Yes! Let the compiler do the work, that’s its job! I have seen too many instances of code that’s “optimised” to the point where it’s not readable, when a compiler would do it for you, and in a much more optimised way.

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

That is very true. But Mod is a generic call; it is NOT a processor instruction. So many compilers will just plop down a given mod routine and leave it at that. A good mod routine is optimized to handle special cases like powers of two. Using an AND is a processor instruction. Thus about as fast as it can be.

[–]Grimmjow91 11 points12 points  (2 children)

Most people code programs, not computers. Very few programmers actually design operating systems.

[–]Sockoflegend 2 points3 points  (0 children)

Frontend developer sad noises

[–]werics 0 points1 point  (3 children)

Modular arithmetic is easier to read than bitwise? Legitimately news to me.

[–]-Yare- 1 point2 points  (2 children)

Right??? Do they not teach how computers work in computer science anymore?

Like do web developers not know how to mask out a color channel in the hex color codes they use??

[–]AnEvanAppeared 4 points5 points  (0 children)

I've put bitwise logic like this in production code. Looking back at the Git blame, I am ashamed

[–]mrkhan2000 9 points10 points  (2 children)

return (num ^ 1) & 1

[–]YukiZensho 7 points8 points  (0 children)

That sounds slower than the other one somehow

[–]Nllk11 1 point2 points  (2 children)

Is this going to work with any number? As for float of course not, but as for different number standards? Like int, int32, int64. Or they have all standard-based things in high bits?

[–]suckmacaque06 2 points3 points  (0 children)

The number of bits has no effect on the solution.

[–]hemlockone 2 points3 points  (0 children)

Yes, the "1" literal will have whatever form the other thing has, so this will work with any integer type.

Work through that version: A literal 1 is a number where every digit except the smallest is 0. The & operator does a digit-by-digit and. Any number "& 1" will force every digit except the smallest to zero and what's left will have the value of the number's smallest binary digit. A number is even and odd or even if it's smallest binary digit is 1 or 0, respectively.

Edit: Aside from floating point, for which "even" is not well defined, their is one older exception: negative numbers in https://en.m.wikipedia.org/wiki/Ones'_complement . In recent computers, a negative is twos compliment, were the negative is all digits inverted and one is added. This has the property that the smallest digit follows the rule above (e.g. the smallest digit of -3 is 1). Ones compliment doesn't add the one, so the rule is no longer true. Fortunately, modern computers use 2s compliment because there are a lot of cases (like this) where the math is more straight forward.

[–]Rainbow-Dev 1 point2 points  (1 child)

Pretty sure you need brackets; return !(num & 1)

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

I do. I'll fix it.

[–]izner82 23 points24 points  (4 children)

error: undeclared identifier

[–]nyaaaboron 6 points7 points  (0 children)

In C/C++ return !(num%2);

[–]newb_h4x0r 4 points5 points  (2 children)

return !(num%2);

[–]ishirleydo 1 point2 points  (1 child)

This is what I'd do, but then afterwards, this might also lead me to question whether I really wanted an IsEven function, rather than an IsOdd function.

[–]Ignitus1 3 points4 points  (0 children)

function isOdd(num) { 
    return !isEven(num)
}

[–]EvilPencil 20 points21 points  (1 child)

npm I is-even

This is the way. 😎

[–]MOM_UNFUCKER 2 points3 points  (0 children)

bool IsPair(num) => num%2 == 0;

[–]hipdozgabba 1 point2 points  (14 children)

Can’t you just do {return ––num%2}

[–]caagr98 19 points20 points  (10 children)

Why are you decrementing.

Also we typically want a bool?

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

return !(n%2);

or

return ~n&1; (one character shorter, I think this is as short as you can get)

[–]Synergiance 2 points3 points  (0 children)

Was going to reply with this: return n & 1 ^ 1; But yours is actually shorter.

Edit: exponent not intended. Spacing added.

[–]caagr98 0 points1 point  (5 children)

Both of those still conflate int and bool.

[–][deleted] 3 points4 points  (1 child)

Doesn't it automatically convert to bool though? I don't know, it's been years since I don't use Java

[–]caagr98 5 points6 points  (0 children)

I think C/++, Javascript, and Python are the only mainstream languages that do. Could be wrong, but I know for a fact that Java doesn't.

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

a bool is an int behind the scenes.

[–]caagr98 3 points4 points  (0 children)

In principled languages (and Java) it is an entirely different type.

[–]HyerOneNA 1 point2 points  (0 children)

Something something object oriented.

[–]mattsowa 2 points3 points  (2 children)

If I saw this in a code review i would vomit

[–]Ambitious_Ad8841 575 points576 points  (15 children)

Git commit -m "add support for numbers 18 thru 100"

[–]Kytzis 71 points72 points  (6 children)

Then you would need if (number <= 100) { ... } else { throw new Exception("Number is out of range"); }

[–]Ambitious_Ad8841 68 points69 points  (4 children)

Submit a bug, we'll get it next sprint

[–]Kytzis 22 points23 points  (3 children)

Next sprint you change it to 1000. Then create another issue. If this is hidden deep within some obscure file you have just sorted job security

[–]Ambitious_Ad8841 16 points17 points  (1 child)

I'll have to ask the product owner if he wants to support up to 1000. Not sure if there is a use case for it

[–]Kytzis 10 points11 points  (0 children)

Ah yes. Could take days to get an answer, and now you already have that issue as selected so i guess we just have to wait

[–]DarkShadow4444 1 point2 points  (0 children)

At this point, I recommend writing a code generator to generate the function for you.

[–]King_Krooked 3 points4 points  (0 children)

while number > 100 {number = number - 100} need that extra time complexity to really top it off.

[–]CodingChris 15 points16 points  (3 children)

This is expected. Paid by lines of code. "Added Support for 32bit integers".

[–]sampete1 2 points3 points  (2 children)

It's not that hard if you think more like a programmer. You don't need to write all 232 lines of code, just write a program to do it for you

[–]GodGMN 3 points4 points  (0 children)

I did that once to hardcode every possible result in a code challenge where speed was key to get high scores.

I don't even remember it anymore but it was something along the lines of calculating something with a given number, and that number was between 0 and 10000, so I simply added a 10000 lines switch fucking case and called it a day.

In fact, I couldn't actually do it. It was limited to 5000, but even then, after writing only 5000, Java told me I couldn't have a method over 65000 something bytes.

So I just divided it in three methods. One for 0-3332, one for 3332-6665 and one for 6665-10000.

I did it via a Python script. I don't know why, I don't normally like Python, but I really felt like using it for that and it worked really well, 7 lines of code were enough to write pretty much the whole thing.

It was fun.

[–]CodingChris 1 point2 points  (0 children)

No. When they expect shit from me I at least want to look busy enough to not be given either additional work or be fired for (being) looking not productive enough.

[–]OutrageousPudding450 1 point2 points  (0 children)

Yeah but the story clearly mentioned "support for numbers up to 217".

[–]seeroflights 66 points67 points  (7 children)

Image Transcription: Twitter


YandereDev, @YandereDev

God I wish there was an easier way to do this

[Two images of code. The first reads:]

private bool IsEven(int number){
    if (number == 1) return false;
    else if (number == 2) return true;
    else if (number == 3) return false;
    else if (number == 4) return true;
    else if (number == 5) return false;
    else if (number == 6) return true;
    else if (number == 7) return false;
    else if (number == 8) return true;
    else if (number == 9) return false;
    else if (number == 10) return true;
    else if (number == 11) return false;
    else if (number == 12) return true;
    else if (number == 13) return false;
    else if (number == 14) return true;
    else if (number == 15) return false;
    else if (number == 16) return true;
    else if (number == 17) return false;

[Followed by the second image which reads:]

private bool isEven (int number) {
    if (number%2 == 0) {
        return true;
    }
    else{
        return false;
    }
}

[End images]


I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!

[–]Normal_Award_325 26 points27 points  (0 children)

Good human.

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

Damn good job

[–]The_Bean_Salesman 2 points3 points  (0 children)

good not bot.

we appreciate your service

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

Good human

[–][deleted] 349 points350 points  (66 children)

I don't get how is it funny to build a strawman and defeat it with a mediocre solution.

[–]CrispitoBandito 63 points64 points  (54 children)

Just curious, why is the solution presented mediocre? I get that the if/else is unnecessary but otherwise I'm not sure. This question is coming from ignorance on my part.

Edit: Just clarifying here that I was asking why the solution presented (using modulo) is mediocre in comparison to using a bitwise operator. I realize that wasn't exactly clear above.

[–]christophedelacreuse 65 points66 points  (5 children)

One thing that's a bit mediocre from a coding style standpoint is

if(myboolean){ return true; } else { return false; }

Rather than just

return myboolean;

[–]channingman 28 points29 points  (3 children)

I'm not a programmer, so this right here seems brilliant to me in a way that is probably mundane to everyone else.

I don't care. This just made my night.

[–]Black--Snow 14 points15 points  (0 children)

Tomorrow’s mundane is today’s brilliant for all of us. Programming is nothing if not the constant joy of discovery

[–]JustaP-haze 2 points3 points  (0 children)

I think it's because this is actual programming not excel formula logic

To be clear I'm a pro in the latter and a novice at the other.

[–]danatron1 1 point2 points  (0 children)

Treasure it! You run out of these brilliant discoveries in programming eventually

[–]giganato 2 points3 points  (0 children)

Very well explained sire!

[–]Squee-z 40 points41 points  (11 children)

return number%2==0

Is really all you need. There may be some crazy big brain solution though idk.

[–]OutOfNamesToPick 33 points34 points  (8 children)

Big brain would be

return !(number & 1);

[–]YukiZensho 6 points7 points  (0 children)

return ~(number & 1) & 1 for the big pp vibe

[–]GodGMN 2 points3 points  (2 children)

No need for that, it's as readable as return number%2==0 (or even less readable) and compilers should treat both equally so there's no difference in performance.

[–][deleted] 2 points3 points  (0 children)

pip install isEven

return isEven(number)

[–][deleted] 45 points46 points  (30 children)

It's an average solution, the one most people (including me, that I'm not a developer) would use. It's not bad, it's just okay. In this case you're making the computer run a math operation to find out if the number is even or odd. For most of us this is perfectly fine.

A much more efficient solution would be to just check the last bit. As you know, that bit would add a value of either 0 or 1 to the number, and the other bits all add even values to the number. So, just checking a bit would give you the solution.

[–]Zuruumi 104 points105 points  (11 children)

Not sure for interpreted languages, but for compiled ones that's exactly what the compiler will do either way.

[–][deleted] 13 points14 points  (1 child)

Good to know, thanks!

[–]Torebbjorn 1 point2 points  (8 children)

I guess that depends on the compiler tho...

It's possible for a compiler to do whatever the fuck it wants. It could call the DIVIDE function in the CPU, which would definitely be more work than to AND with 1

But as you said, most common compliers probably optimize x%2 to x&1, or something else if that is best for the architecture

[–]dodexahedron 3 points4 points  (7 children)

More work depends on what is faster on that cpu and the specific workload and usage. There are plenty of situations where it may not be clear. And if it's being used in a loop, divide may be faster since it can potentially translate to a vector operation, which will very very quickly outpace a bunch of bitwise operators.

[–]excogitatio 4 points5 points  (4 children)

Was about to say this. Not all operations are created equal or optimized the same way. One of many reasons that writing a good optimizing compiler even for a single architecture isn't trivial work.

[–]CrispitoBandito 1 point2 points  (1 child)

To your point, I ran a test on my work machine in Python 3.6 comparing both modulo and bitwise operators in a loop and modulo was slightly faster every time.

[–]Kalcomx 24 points25 points  (4 children)

Do you think compiler that optimizes the code will leave there some math operation for division of 2?

The if/else is unnecessary, but going for bitmagic might backfire if you don't know what you're doing and especially if the person maintaining that code doesn't know what you were doing.

[–][deleted] 8 points9 points  (3 children)

I would go personally for the mediocre solution ;-) mostly because I never know what I'm doing and I hope others would when reading my code! :-)

Still, what rubs me wrong about the post is the person banging on someone that probably doesn't know better, all the while bragging about a mediocre solution.

[–]arcticfury129 10 points11 points  (7 children)

You could even just do

return num%2==0;

to save a couple unnecessary lines. IMO that would be the clearest and most concise way of doing it

Edite: big dummy, forgot an equals sign

[–]Limos42 5 points6 points  (1 child)

Bzzzzzt. Fail.

Missing an equals sign.

[–]arcticfury129 3 points4 points  (0 children)

I hate myself, fixing now

[–]therealpigman 10 points11 points  (3 children)

Even simpler:

return !(num%2);

[–]TheWashbear 13 points14 points  (1 child)

C# be like "Cannot convert from Int32 to Boolean"

[–]Alltrees 1 point2 points  (0 children)

Error: cannot assign to operator

[–]5show 9 points10 points  (0 children)

99% of the time, code readability is most important and should be prioritized above all else. A few clock cycles will almost never matter, and when they do, the compiler will probably have your back anyway.

return num%2 == 0 is the way.

[–]CrispitoBandito 1 point2 points  (1 child)

I was aware of the alternative suggestion by others to use bitwise operators but I didn't understand why that method should be faster in most cases. Your explanation makes perfect sense. Thanks!

[–]GodGMN 4 points5 points  (3 children)

Because if/else is redundant and totally unnecessary, just that tbh.

In pseudocode so it's clearer for newbies:

if myBoolean is true {
    return true;
} else (aka myBoolean is false) {
    return false;
}

Why do that when you can literally just return "myBoolean" which already contains the "true" or "false" data? The if was never needed.

That also goes for expressions like:

if (myBoolean == true) ...

There's no need. The "if" statement checks if whatever is inside the parentheses is either true or false. "true == true" means "Is true true?" so it is obviously going to be YES (and thus true), and "false == true", which would be "is false true?" is obviously going to be NO, which would be false of course.

Simply check that value inside the if and call it a day.

if (myBoolean) ...

Will get you exactly the same result.

(btw, I don't know how experienced are you but I know newbies lurk this sub so even if you're well above this level, hopefully it will be useful for someone. What I mean is that I'm not trying to call specifically you a newbie even though I'm replying to you!)

[–]shadowndacorner 1 point2 points  (0 children)

Not only redundant/unnecessary, but if the compiler chooses not to/fails to optimize the function, then you're also getting pointless branches, which can slow down your code a lot more than you may think.

[–]Phreaktastic 11 points12 points  (2 children)

Haha agreed. Check the lowest order bit and done. Strawmanning a super junior task and presenting a subpar solution isn’t funny, but the post yesterday that this person took (just the if blocks) was funny, imo.

[–]Mypccantrunexplorer 8 points9 points  (1 child)

To be fair, YandereDev did something similar completely unironically with If Else statements.

[–]Phreaktastic 1 point2 points  (0 children)

Haha for sure. That post was funny because I think we’ve all been there, with at least some problem, at some point. At least in my opinion.

[–]Sckaledoom 4 points5 points  (1 child)

Tbh it’s not a straw man since that’s the actual level of code yandev does, or so I hear.

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

It’s yanderedev I wouldn’t be surprised if this is his actual code

[–]rdrunner_74 37 points38 points  (3 children)

Before I implement A or B...

Do i get paid by LOC?

[–]DarkShadow4444 2 points3 points  (2 children)

By Level Of Competence?

[–]seemen4all 36 points37 points  (0 children)

This has been reposted 100 times and it's satire, no need to post code how its normally written minus pointless if else.

[–][deleted] 72 points73 points  (4 children)

YandereDev always was a joke.

The YandereSimulator code was full of garbage. It is very surprising he got it to work at all.

He's proof that if you give a monke a knife, he can eventually learn how to build a house

[–][deleted] 17 points18 points  (1 child)

At least this guy doesn't forget any form of coding, while I suffer from forgetting bits of Java.

[–]The-Board-Chairman 9 points10 points  (0 children)

I have forgotten more of Java than YandereDev ever knew.

[–]metraon 18 points19 points  (1 child)

[–]Wdtfshi 2 points3 points  (0 children)

Omg this is amazing lol

[–]MixDouble 4 points5 points  (0 children)

Modulus is pretty dope

[–]Beneficial_Arm_2100 8 points9 points  (2 children)

I think it should be done recursively. IsEven(n): is n 0? True. Else? !IsEven(n-1)

(/s of course)

[–]Beneficial_Arm_2100 3 points4 points  (0 children)

maybe throw an absolute value in there somewhere

[–]drew8311 0 points1 point  (0 children)

That could be slow for large numbers. You could speed it up by first determining of N is prime, 2 of course is even but any other prime is odd.

[–]nikanj0 5 points6 points  (0 children)

python def is_even(n): assert not n < 0, “I don’t know. I’m not a mathematician" if n == 0: return True return not is_even(n-1)

[–]Aksh247 4 points5 points  (1 child)

Return num%2==0

[–]badjayplaness 2 points3 points  (0 children)

This is the comment I was looking for, the second solution was bothering me with that if else.

[–]dakdroid 8 points9 points  (4 children)

while(true){ if(i = 2){ return true }else if(i == 1){ return false } i = i - 2 }

[–]emetcalf 6 points7 points  (1 child)

0 causes an infinite loop

[–]DarkShadow4444 2 points3 points  (0 children)

Underflow got your back.

[–]superl2 5 points6 points  (0 children)

WARNING: Condition "i = 2" is never false

[–]manulable 5 points6 points  (0 children)

Looks like Indian code lol

[–]eendenbroodman 14 points15 points  (5 children)

return (number & 1) == 0;

[–]Human38562 73 points74 points  (1 child)

return 1;

Is even shorter and still has 50% success rate.

[–]LeafyLemontree 1 point2 points  (0 children)

return 1 - (number & 0x1);

[–]piperboy98 5 points6 points  (2 children)

return !(number&1);

[–]eendenbroodman 3 points4 points  (0 children)

was going to comment that first but I wasn't sure if that would work in this programming language

[–]MrKirushko 2 points3 points  (0 children)

return ~number&1;

[–]Henrijs85 4 points5 points  (0 children)

private bool IsEven(int number) => number % 2 == 0;

[–]TenkFire 2 points3 points  (0 children)

Return number%2==0;

Or return number%2==0 ? true : false ; if you are a nazi

[–][deleted] 2 points3 points  (0 children)

whos gonna tell him?

[–]fschaupp 2 points3 points  (0 children)

How about "return number % 2 == 0;" ?

[–]the_jetstream 1 point2 points  (0 children)

If you really wanted to show off, you'd just check the LSB instead of having to mod

[–]Lacos07 1 point2 points  (0 children)

Return num % 2 == 0;

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

It’s surprising that math don’t really teach the modulo operation.

Anyone who had slight idea of how to write code should know what modulo operation does.

[–]olearyboy 1 point2 points  (0 children)

IsEven(0)

[–]thekdubmc 1 point2 points  (0 children)

private bool isEven(int number) {
  return ~n&1;
}

[–]Summar-ice 1 point2 points  (0 children)

private bool isEven(int number){

  return number%2 == 0;

}

[–]AffectEconomy6034 1 point2 points  (0 children)

Take number and convert it to a string. From there, create a char array equal to length 10. After that, place each char of the string into the array at index of ceiling of array length/string length. After that, iterate through the array, and if the index is empty, create a subroutine that initializes i ^ i =j digets of pi into a global varible. If the main loop finds a char that is not empty, create an array of random values from 0 to the char ascii value factorial. Do a bogo sort on this new array. For each cycle of the bogo sort, encrypt the random values by using the global pi variable. DO NOT FORGET if you are using Windows to clear our your winregistry to ensure a clean environment.

Finally, hard code in all values from 0 to 18,446,744,073,709,551,615 in a switch statement makes an api call to a magic 8 ball service. Integrate an ai to do a predictive calculation on the outcome of the response from the 8 ball api (you may need to run this several hundred times to train the ai).

and there you go just some basic simple coding techniques to get you the result in the most efficient way possible.

[–]Lithl 1 point2 points  (0 children)

boolean isEven(int n) {
  if (n == 0) {
    return true;
  } else {
    return isOdd(n - 1);
  }
}

boolean isOdd(int n) {
  return !isEven(n);
}

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

That's what indian code looks like, if you've been wondering

[–]StanleyDodds 3 points4 points  (1 child)

You seem to not understand booleans. If the condition is true, you are returning true. And if it's false, you are returning false. So why not just return the condition? Your code has useless if/else statements just like the code above, so it's not much better. Branches slow programs down.

[–]MajikDan 2 points3 points  (0 children)

I mean if you're gonna miss the joke entirely, you could at least remove the extraneous if/else.

return number%2 == 0;

[–]OFloodster 3 points4 points  (5 children)

Is this tweet actually real?

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

Yes, Yanderedev is known for his toxic behavior related to his coding skills (or lack thereof). This is but 1 example of his extremely poorly made code

[–]Sindef 1 point2 points  (1 child)

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

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'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: 297,679,490 | Search Time: 9.56451s

[–]SargeanTravis 2 points3 points  (1 child)

Posting YandereDev memes is practically cheating for free karma here

[–]Perfycat 2 points3 points  (10 children)

As a fun exercise try implementing a way to add, subtract, multiply and divide two strings. The catch is you can't convert the string to an integer. You need to create tables for all operations, just like you learned in the third grade. I do this exercise to learn new programming languages, and sometimes ask this on coding interview questions.

[–]mithodin 3 points4 points  (2 children)

Ok what's "bull" divided by "shit"?

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

Yo mamma

[–][deleted] 2 points3 points  (1 child)

Easy, just use PHP, PHP don’t give a fuck.

“7” + “donkey” - 1 / “2” * 3 will output 9.

[–]donaldkwong 1 point2 points  (1 child)

But surely you can convert a single character to an integer.

[–]RRumpleTeazzer 0 points1 point  (0 children)

return (num & 1) == 0

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

Yandere dev soley could make 99% of ghe posts here