What's the worst code you've ever come across?

StageLeft

No Lifer
Sep 29, 2000
70,150
5
0
I'm doing maintenance on a project now and it runs in a production environment. I've seen in this project an "On error resume next" followed later on in the page by a line of code which always has and always will give an error. I spent about 10 minutes wondering how the hell it wasn't blowing up one day when I looked way up high and found the on error resume next. I guess that the original devs couldn't figure it out so they just ignored it.

Just now I have a line where an object is being created and then the line after it is totally unrelated to this new object, then the line after that is killing the object. This happens twice on the same page!
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
MySQL Administrator. The GUI version crashes once every 30 seconds from memory errors. Still, its faster than doing it by hand.
 

Jack Ryan

Golden Member
Jun 11, 2004
1,353
0
0
High priced consultants (before I got there of course) provided code where instead of using an oracle index field, they concatenated strings and used LIKE. Um, needless to say when we fixed that our program sped up dramatically.
 

yukichigai

Diamond Member
Apr 23, 2003
6,404
0
76
When I was modifying Tribes from an existing mod I found loads of interestingly dumb code, particularly some of it relating to simulated "timed" effects. One of the better examples was a recursive function simulating EMP effects (no energy for flight or energy weapons) where the author had neglected to include a check to reset the time to 0 if the player died, but had set it up to stop checking if they were dead. What this meant was that if you died while you were EMP'd you effectively became EMP-immune. Good way to unbalance the game.

A similar effect created problems with a speed and strength boost effect that was in reality just an armor change. Because the timed effect provided a minimal boost of health at a set interval a dead boosted player's body would wind up re-animating, though they wouldn't be able to control it and the game would still consider it "dead". This meant that in 30 seconds the body would disappear, but it also meant if you could get it to hold something within those 30 seconds whatever it was holding would disappear as well. And the number one thing people threw to a re-animated corpse? The Flag, when playing Capture the Flag. Sure, it would reset to the flagstand in a few minutes, but for those few minutes the other team couldn't make a flag capture.

The best one though was the way the guy coded in "lockjaw" missiles. (Where you locked onto someone once and for the next 15 seconds every missile you shot sought them out) He used a specific type of projectile, but instead of creating an emitter to shoot it he used the generic "spawnprojectile" command. The problem with this was that for that projectile type "spawnprojectile" didn't return the ID of the projectile, which wouldn't expire and remove itself. Ever. (It was normally handled by the emitter) After 5 or 6 people used lockjaw the game would get incredibly laggy whenever you viewed an area where a lock took place, as your computer attempted to calculate collision details for dozens of invisible, hundred-unit-long projectiles.

Yes, stupid code is fun. :p
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
I see horrible code every day, so I don't even really pay attention anymore. I've given up on trying to maintain any notions of quality, because it seems to be a myopically utopian motive in this volatile industry.

I largely feel that the cause is the dichotomy of artistic expression vs. engineering discipline. The latter feel there's no notion of determinism in development, and the holistic functional qualities are what count. In contrast, the engineering discipline is more reductionistic. I'm more of the reductionist, but my continued conflict with those opposed has left an overwhelming attrition on my personal interest.

I also believe that part of the problem is that customers often have absolutely no measure of quality for their discernment. The multisensory experience of sitting in a Ferrari relative to a Ford Festiva leaves an immediate impression of quality difference, but customers of technology systems are left with only one: Does it work? If it works, then it fulfills the business objective, and as a result the esoteric quality that achieved that result becomes immaterial. This undermines the concerns of developers who know the damn difference between the Ford Festiva and Ferrari of software. You're left with a product that succeeds only out of the ignorance of the customer.

Bah. Sorry for the rant.
 

acemcmac

Lifer
Mar 31, 2003
13,712
1
0
a very long chain of disfunctional if/else statements (10 pages) for a text based RPG in a C++ class. It got an F.
 

silverpig

Lifer
Jul 29, 2001
27,703
12
81
:() { :|: & } ; :


Go ahead... try it :)


PS: it's a bash thing (linux) and well... heh... :)

PPS/caution: know what a fork bomb is? It's not dangerous, but it does tie some stuff up...
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
A horrible mix of C/C++/Fortran that had evolved over at least 20 years on platforms including Cray, Sun, SGI, VAX and Windows. One of the nicer features was the way they shared data between the C/C++ part of the code and the Fortran part. They grabbed big chunks of memory, then allocated from that. Then to pass the "object" from C->fortran or vice versa, they'd give a pointer to the start of the block and an index telling you how many objects to count into the block for the one you wanted. Was an absolute nitemare to debug. Now here's the fun bit ... the object sizes were a hodge podge of hard-coded values, and sizeof calls. This is for several dozen different, and in some cases nested data structures. Of course, switching between platforms and compilers (I was porting the app to Linux) can result in the objects being aligned differently, and therefore the size changes. A very subtle and difficult to track and reproduce error is the result.

Fixing their whole memory allocation scheme was beyond the scope of the project. I ended up manually aligning the structures and wrote a script to go through the source tree and check that everything would end up aligned correctly given the current compiler & platform.
 

NuclearNed

Raconteur
May 18, 2001
7,881
378
126
I don't have any specific examples, but just some things my boss does that drives me crazy. For example, she doesn't like (and therefore doesn't use if at all possible) loops, nested ifs, arrays, or dot notation. Because of this, some of her code is really wacky because of all the convolutions she goes through to avoid the usage of the above items.

I have quizzed her about this, and the only reply she gives is that she "doesn't like those things". This only makes sense coming from the mouth of a female. <sigh>
 

DWW

Platinum Member
Apr 4, 2003
2,030
0
0
worst code...thats easy...any C++ code

*ducks*

I find it scary when someone is an industry "professional" (I know one who has been doing enterprise software for 6 years) who hasn't read a few books that I consider basic knowledge: Introduction to Algorithms, Programming Pearls, Pragmatic Programmer, The Practice of Programming, Code Complete, Building Secure Software, Secure Code and a few others (depending which way you want to go, stuff like design patterns and whatnot). I'm not suggesting you agree with all material covered but when I open a rant or discussion with another programmer, I expect there to be a certain level of knowledge. Because many people don't read into the accepted "conventions" much, their code suffers and especially when they are developing some classes...their OO approach just baffles me :p
 

yukichigai

Diamond Member
Apr 23, 2003
6,404
0
76
Originally posted by: Yaotl
Originally posted by: Cheeseburger
idkfa

at least that made a little sense, id keys firearms ammo
The other one was ID Smashing Pumpkins Into Small Piles Of Putrid Debris. It's a refference to the game of the same name. (minus the ID) Weird little game too.
 

SWScorch

Diamond Member
May 13, 2001
9,520
1
76
I don't know, but I can guarantee it was mine :) I wrote a backup program a while ago, and wrote a recursive function to enumerate all files and folders on a hard disk, and that thing was so convoluted... I suck at logic, so it was messy and redundant and very, very loopy. It was around 3-4 pages of code, and later on, when I knew what I wanted better, I re-wrote it as about half a page.
 

Kntx

Platinum Member
Dec 11, 2000
2,270
0
71
this project im working on now... originally it was outsourced to india... we're fixing it, but it's next to impossible.

there are...

-1000+ global variables, all with cryptic indian names.
-goto's galore.
-nested if statements 30 and 40 layers deep

lots of stuff like..

if(!something)
{
}
else
{
// code here
}

-functions that are called all over the place.. but when you go to the definition the entire function (sometimes 500 lines+) is commented out

-in a few cases after all the commenting.. functions will be hardwired to return -17 or something stupid, and if you change it to any other number the program won't work.

- there's this one global.. that is used all over the place, but they're using crazy bitwise operations to store a bunch of yes/nos in an int.


anyways.. it's just the worst thing ever. and im working on canada day. boooo.