[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

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

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 75
Thread images: 10

File: BS in CS.png (41KB, 890x670px) Image search: [Google]
BS in CS.png
41KB, 890x670px
What was the worst piece of code you've ever laid your eyes upon?
>>
>>56887627
https://www.daniweb.com/programming/software-development/threads/440954/can-t-fix-error-in-my-program
>>
>>56887711
What the actual fuck. That gave me cancer
>>
File: Screenshot_20161002-104602~2.png (145KB, 1080x1328px) Image search: [Google]
Screenshot_20161002-104602~2.png
145KB, 1080x1328px
>>56887711
Oh fuck is this where that meme came from?
>>
>>56887627
Don't know shit about programming. Is there something that basically would take all even numbers, This seems pretty inefficient, just trying to learn.
>>
>>56888039
Learn the definition of an even number.
>>
>>56888064
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
>>
>>56888159
Modulus. man.
If it equals one, odd. If it equals zero, even.
>>
>>56888159
More precisely
>If number has remember 0 when divided by 2 then output number is even
>>
>>56888187
>remember
>>
My own.
>>
>>56888184
Fuck I totally forgot about that. Thanks senpai
>>56888187
Remember?
>>
>>56887627
>Enters 102
>Your number is odd
>>
>>56888232
Same tbqh
>>
>>56888232
Code reviews make me feel stupid
>>
>>56888039
float x;
if (x/2 == int(x/2)) return "even";
else return "odd";
>>
>>56888184
>>56888288
Slow and inefficient. Do bitwise AND with 1 to check if number is odd.
>>
>>56887711
It's fucking great .
>>
>>56888039
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.
>>
>>56888288
Wish I had the patience to get into this on my own. What language is this btw.
>>
>>56888337
it's C i think
>>
>>56888221
Remainder
>>
>>56888039
> Is there something that basically would take all even numbers

https://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;
>>
>>56888288
:^)
If Number rem 2 = 0 then 
Put_Line("Even");
end If;
>>
int x
scanf("%d", &x)
printf("%s", (x % 2 == 0)? "even", "odd");
>>
File: 1475335685172.png (236KB, 1204x776px) Image search: [Google]
1475335685172.png
236KB, 1204x776px
>>56887627
STAND ASIDE

fresh from >>>/sci/
>>
>>56888460
Jesus fuck
>>
>>56888307
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.
>>
>>56888039

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.
>>
>>56888460
We should start a new /g/ thread where we post these images along with correct solutions (or better yet, even worse solutions).
>>
>>56888460
holy fuck
link to thread?
>>
>>56888288

if(x % 2 === 0) {
document.write("Even Steven! XD";
}
else {
document.write("That's odd, Todd! haha");
}
>>
>>56888307
>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.
>>
>>56888502
it might not be that fresh tobeqfh
>>>/sci/8384105

never seen it before though
>>
>>56888511
I think you missed the joke there, buddy.
>>
>>56888495
If you need to keep the function call format, even though it's disgusting, you just logical or the inputs and return.
>>
>>56888039
if (!(num & 1)) {
// Number is even
}
>>
>>56888511
x = y % 2 ? 0 : 1;
>>
File: Capture.png (60KB, 1099x726px) Image search: [Google]
Capture.png
60KB, 1099x726px
The scary thing is that your life might depend on code written by these people.
>>
>>56888522
>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
>>
>>56887627

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.
>>
>>56888307
>>56888557
This is a great way to make code less readable while adding no value whatsoever.
>>
>>56888639
>tfw your pacemaker's control software was written in Visual Basic
>>
File: when_girls_code.jpg (226KB, 869x1776px) Image search: [Google]
when_girls_code.jpg
226KB, 869x1776px
Look at that horrible code on the left. It was probably written by a fucking white male!
>>
>>56888460
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
}
>>
File: homer.jpg (21KB, 576x432px) Image search: [Google]
homer.jpg
21KB, 576x432px
>>56888646
>A bug in the threading was caused by a poem written by one of the developers kids in the comments commenting over some variables.
>>
>>56888668
> ^_^
>>
>>56888668
>return 5 because I'm so random yay :D
This is shooped, right?
>>
>>56888704

That image is a troll.
>>
>>56887627
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
>>
>>56888648
Depends on your priorities. I work on real-time systems so we do stuff like this all the time.
>>
>>56888664
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.
>>
>>56888793
Even the shittiest compiler will optimize that comparison. It's just a bad habit that serves no purpose.
>>
>>56888639
Who still uses pascal?
>>
File: the best BS in CS.jpg (37KB, 694x801px) Image search: [Google]
the best BS in CS.jpg
37KB, 694x801px
>>56887627
>>
>>56888793
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.
>>
>>56888851
It's not Pascal.

That is also part of the problem.
>>
>>56888668
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...
>>
File: pas_grid.png (38KB, 1406x392px) Image search: [Google]
pas_grid.png
38KB, 1406x392px
>>56887627

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

pic related.
>>
>>56888645
even and odd only contains integers so what's the problem?
>>
File: 1347247820055.jpg (1MB, 1920x1080px) Image search: [Google]
1347247820055.jpg
1MB, 1920x1080px
>>56888889
>imblying that uncommented, undocumented code is superior just because it's shorter
ishygddt
>>
>>56888307
I bet you fell for the 'xor variables to swap them' meme
>>
>>56887627
the windows nt source, not joking.
>>
>>56889390
It is commented... the original one said: "What the fuck" in the i = 0x5f3759df - (i >> 1); line
>>
>>56887627

I've seen the source for Adobe Photoshop. I still have nightmares about it
>>
>>56889669
Give us an example, annon!
>>
>>56888854
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
>>
>>56888425
Or:
$even = $var % 2 == 0
>>
>>56887627
>not doing if userNumber in [2,4,6,8,10...100]
>>
>>56890439
abs(usernumbe)r -= 2 while abs(usernumber) > 0
return usernumber == 0
>>
>>56890439

m8 it's easier than that. You can solve it with basic math.
>>
>>56890439
>not doing if(userNumber % 2 == 0)
>>
>>56888676
how about
function atLeastOneTrue() {
return [].reduce.call(arguments, (prev, curr) => prev || curr, false);
}
>>
>>56888232
this
Thread posts: 75
Thread images: 10


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.