What was the worst piece of code you've ever laid your eyes upon?

What was the worst piece of code you've ever laid your eyes upon?

Other urls found in this thread:

daniweb.com/programming/software-development/threads/440954/can-t-fix-error-in-my-program
en.wikipedia.org/wiki/Modulo_operation
twitter.com/SFWRedditGifs

daniweb.com/programming/software-development/threads/440954/can-t-fix-error-in-my-program

What the actual fuck. That gave me cancer

Oh fuck is this where that meme came from?

Don't know shit about programming. Is there something that basically would take all even numbers, This seems pretty inefficient, just trying to learn.

Learn the definition of an even number.

I know what an even number is mate. Could yoou do something like this:
>if number can be divided by 2 then output number is even
pls no bully

Modulus. man.
If it equals one, odd. If it equals zero, even.

More precisely
>If number has remember 0 when divided by 2 then output number is even

>remember

My own.

Fuck I totally forgot about that. Thanks senpai
Remember?

>Enters 102
>Your number is odd

Same tbqh

Code reviews make me feel stupid

float x;
if (x/2 == int(x/2)) return "even";
else return "odd";

Slow and inefficient. Do bitwise AND with 1 to check if number is odd.

It's fucking great .

if(/2|4|6|8/.test(number.toString().split('')[number.length])) console.log('even')

Something most anons can agree with at this point is to remove the inline archive.

Wish I had the patience to get into this on my own. What language is this btw.

it's C i think

Remainder

> Is there something that basically would take all even numbers

en.wikipedia.org/wiki/Modulo_operation

Finds remainder after division. Only odd numbers leave remainders. So if you check the modulo of a number and it returns a remainder, it's an odd number and if no remainder it's an even number.

In php, $even = $var % 2 ? false : true;

:^)
If Number rem 2 = 0 then
Put_Line("Even");
end If;

int x
scanf("%d", &x)
printf("%s", (x % 2 == 0)? "even", "odd");

STAND ASIDE

fresh from

Jesus fuck

Daily reminder that doing this will do nothing for performance since thw compiler isn't retarded, but will make the code less understandable, especially to beginners, and if you do this, you are just showing off your epeen with no merit.

You have to think of it terms of 'is there a test that I can do which will always tell me if a number is even?'

Such as: 'All even numbers can divide into two equal parts' - so if you divide the number by two and get one left over then it's odd.

We should start a new Cred Forums thread where we post these images along with correct solutions (or better yet, even worse solutions).

holy fuck
link to thread?

if(x % 2 === 0) {
document.write("Even Steven! XD";
}
else {
document.write("That's odd, Todd! haha");
}

>Slow and inefficient. Do bitwise AND with 1 to check if number is odd.

... I think the fastest way then would be to read the least significant bit. But I think that only works with integers.

it might not be that fresh tobeqfh
never seen it before though

I think you missed the joke there, buddy.

If you need to keep the function call format, even though it's disgusting, you just logical or the inputs and return.

if (!(num & 1)) {
// Number is even
}

x = y % 2 ? 0 : 1;

The scary thing is that your life might depend on code written by these people.

>I think the fastest way then would be to read the least significant bit.
You can't just read one bit from memory though, you have to read one or more bytes and extract that bit with bitwise operators.

>But I think that only works with integers.
True

A company that I was at a few years ago gleefully told me that they were 'approaching 1 million lines of code'.

When I got to the code I found 50 files containing about 20,000 lines each.

The company had never performed any kind of QA or Code review in 8 years.

A bug in the threading was caused by a poem written by one of the developers kids in the comments commenting over some variables.

This is a great way to make code less readable while adding no value whatsoever.

>tfw your pacemaker's control software was written in Visual Basic

Look at that horrible code on the left. It was probably written by a fucking white male!

what a shitty code!
function atLeastOneTrue(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z){
if(Array.prototype.slice.call(arguments).reduce((fu, fug) => fu+fug)) return true
if (!Array.prototype.slice.call(arguments).reduce((fu, fug) => fu+fug)) return false
}

>A bug in the threading was caused by a poem written by one of the developers kids in the comments commenting over some variables.

> ^_^

>return 5 because I'm so random yay :D
This is shooped, right?

That image is a troll.

I don’t think this is real honestly

I think I was thirteen when I first had to do this, and I was smart enough to compare rounded and unrounded quotients

Depends on your priorities. I work on real-time systems so we do stuff like this all the time.

Nothing wrong with Visual Basic per se, it's good for simple UIs as long as you know what you're doing.
Of course, you don't want to make pacemaker *firmware* with it.

Even the shittiest compiler will optimize that comparison. It's just a bad habit that serves no purpose.

Who still uses pascal?

...

Trust me, compilers these days are smart enough to omit division instructions when it encounters a % 2.
If your compiler doesn't to that it's probably from the 70s or something and you might consider upgrading.

It's not Pascal.

That is also part of the problem.

The left code is what happens when you let only white male work on your program,... not asian, pajeet, woman who code or fat feminist... that's what you get...

A piece of code written in Pascal from 1995. And they needed was some simple math, but instead they opted for stupidity.

pic related.

even and odd only contains integers so what's the problem?

>imblying that uncommented, undocumented code is superior just because it's shorter
ishygddt

I bet you fell for the 'xor variables to swap them' meme

the windows nt source, not joking.

It is commented... the original one said: "What the fuck" in the i = 0x5f3759df - (i >> 1); line

I've seen the source for Adobe Photoshop. I still have nightmares about it

Give us an example, annon!

tfw had to learn C from old ass faggots who insisted that we only use a specific extremely weird compiler, in linux that we had to download and use no other compiler.
>start writing overloading functions
>they compile in the compiler im using
>try the course compiler
>it doesnt work
>try a different one
>it works
>lecturer tells me it needs to compile in their compiler
>compiler buggy as fuck
>realise it was caused by a blank space character after an end like character causing the compiler to shit itself
>CS never again
>i was studying engineering

Or:
$even = $var % 2 == 0

>not doing if userNumber in [2,4,6,8,10...100]

abs(usernumbe)r -= 2 while abs(usernumber) > 0
return usernumber == 0

m8 it's easier than that. You can solve it with basic math.

>not doing if(userNumber % 2 == 0)

how about
function atLeastOneTrue() {
return [].reduce.call(arguments, (prev, curr) => prev || curr, false);
}

this