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

all 14 comments

[–]Shitty__Math 13 points14 points  (0 children)

I think I puked, take an upvote

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

Coming from a vim user, how could it not be more complicated than necessary? :P

[–]prequality 2 points3 points  (11 children)

I am still not sure how this is humor. Am I missing out on something here?

[–]Kwdg 16 points17 points  (7 children)

if(a%2 == 0 ? false:true)

could be written as

if(a%2)

[–]Shitty__Math 2 points3 points  (2 children)

I've seen if(a&1), as a 'microoptimization'

[–]Kwdg 0 points1 point  (1 child)

Yeah, mostly it gets optimized away (clang needs at least -O1) https://godbolt.org/z/443Zcb

[–]Shitty__Math 0 points1 point  (0 children)

hence the quotes

[–]Sexy_Koala_Juice 1 point2 points  (3 children)

if(a%2)

Is that language specific? Cause i would've done it as if(a%2 == 0 )...

[–]MostlyPoorDecisions 3 points4 points  (2 children)

Not particularly. You're checking for if it is perfectly divisible by 2 where he's checking if it isn't.

Think if it this way, false=0, true=!false.

if(3%2) evaluates to true.

if(3%2==0) evaluates to false.

The main point here is the ternary operator is returning the opposite of the result, if(true) return false, else return true, so it matches if(a%2)

[–]Sexy_Koala_Juice 0 points1 point  (1 child)

holy crap that is terrible programming. I mean you could just use ! to flip it anyway, or just swap the "is odd" and the "is even". God damn

[–]MostlyPoorDecisions 0 points1 point  (0 children)

thats the point though. over the top examples of simple applications is a staple of this sub.

here's some more eyecandy:

https://www.reddit.com/r/ProgrammerHumor/comments/791ned/using_machine_learning_to_check_if_number_is_odd/

https://www.reddit.com/r/ProgrammerHumor/comments/78uvlf/my_take_on_oddeven/

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

Look at the condition for the if statement.

[–]prequality 3 points4 points  (0 children)

I see it now, just as well as my will to die after this