Home >
QOW: What is the worst code you have ever seen?
Recently, I was discussing some developer horror stories with some co-workers. Kevin Schmidt was telling me about a support/enhancement contract from a major company that he had to walk away from because he just couldn't deal with the code he was asked to work on. Upon further prodding, he told me that the project he was asked to work on was a Flex application that consisted on 10,000+ lines of code, all of which were in the main application MXML file. That's right one file for the entire application. Worse yet, it was riddled with state management code that made the whole thing impossible to work on. Since we have all run into code like this over our career, I thought it might be fun to hear some of your stories on this topic.
Don't be afraid, if your coding horror story is your own code that you revisited years later. I have never met a developer who is truly proud of their code from 3-5 years ago, and it they are it usually means that they are not growing as a developer.
Want to write for InsideRIA.com? Follow me on Twitter for exclusive topic requests/




Facebook Application Development
Not the worst ever, but nice and short (in ActionScript 3):
public function get loggedIn():Boolean
{
return Object(parent).loggedIn;
}
I ran into 30k in 1 file, but at least it was separated from the mxml.
The magic "gotoAndStop(currentFrame)" from a cheap freelance :
carnet._londres.gotoAndStop(carnet._londres.currentFrame);
carnet._bresil.gotoAndStop(carnet._bresil.currentFrame);
carnet._bangkok.gotoAndStop(carnet._bangkok.currentFrame);
I've blogged it : http://www.remitoffoli.com/blog/2009/10/05/freelance-fail-gotoandstopcurrentframe/
:)
i once found a bug in my coworker's nested ternary statements. i'm not sure nesting ternaries is ever justified - kind of defeats the point of the brevity and readability of the expression. this example really cemented my feelings about that.
I once fought a 700 line function that was full of conditionals. Half a day into unraveling the code it become clear that it was also recursive. Nice.
I absolutely hate getting code that has
myvar_1
myvar_2
...
myvar_406
myvar_407
And then you get a condional
if (myvar_1) {
myText_1 += 'foo';
}
if (myvar_2) {
myText_2 += 'foo';
}
aaauugh!
I did a code-review for a guy who was trying to parse lots of lots of XML files (about 3,000 a day). He was looking for just a few keys out of the entire bunch of them, so it should have been no problem. His platform of choice was ColdFusion... His solution :
1. Open and parse each XML document in a directory, and scan through it. Look for a string while looping over each line in the document using FindNoCase
2. If he found the string, he would then copy the file to a new directory.
3. After he is done scanning the first set of files, he would then move to this second directory and scann of it's files. Again, searching for another string, going through each document, line-by-line.
4. Next, if he would find the second string in the document, he would then copy the file to a third directory.
5. Next, he would scan the third directory, open each file, and parse out the XML node he wanted. He would write that value to a database.
The process he came up with ended up taking about 35 - 40 minutes. With the re-write, we brough it down to 90 seconds. Oh, and this was only one of the processes he let us review... He had about 30 or so more that we didn't even open :P
Following on from Amy's example, I once encountered a 4000 line Visual Basic function which opened every table in the database. Each table was called "myTable1" up to "myTable40".
To make it worse, some of the data fields used strings as flags, so you would get "if (variable == 'x')", with no indication as to what x was
Oh, and conditionals nested up to five times, including one covering about 300 lines.
Sample code shown in an interview:
private function showAnswer():void
{
if(currentQuestion.i != '')
{
}
else
{
this.currentState='showAnswer';
}
isAnswer = true;
}
private function showAnswer1():void
{
if(currentQuestion.i != '')
{
}
else
{
this.currentState='showAnswer1';
}
isAnswer = true;
}
private function showAnswer2():void
{
if(currentQuestion.i != '')
{
}
else
{
this.currentState='showAnswer2';
}
isAnswer = true;
}
...
Windows operating system
The worst code I have ever seen is my own. I'm been leaning how to program for 10+ years. Everyday I learn about the things that I didn't understand the day before. It has taken a long time to learn what I know now. The most frustrating part of it is that people with just starting out can get up to speed with far less effort than I had to put in because the resources for learning are so much better today now then they were. It's a good thing and I will continue to struggle to become better.
This is a simple segment to a 1,500 line .mxml file that dynamic modifies the UI based on a radio button selection and builds two large XML objects for PDF rendering:
dataXML.LastName = first_name.text;
dataXML.FirstName = last_name.text;
Regarding the above example, there were eight individual files that duplicated the functionality soooo... you got it - the error shown above and all the other errors existed in eight files.
Worst thing I saw was in a project I had to take over.
The culprit (whom I've never seen) put something like 300+ lines of HTML in a Javascript string.
Each line being a concatenation (page += "...").
And then, he finally decide to "document.write-it" at the end.
I really thought it was a joke when I opened the file for the first time (everything in a string means no indentation, no code colorization, a real pleasure when you have to debug it...).
It could have been funny if it was the only one... It wasn't.
I finished by writing a script to clean them all, great waste of time.
And it's just a small sample, every file of this application was a joke, maybe someday I'll write a book about it, it really deserve it.
@John Lindquist : I really love yours, made me laugh =)
Once I wrote this T__T
//....
if ( booA == true ) {
booB = true;
else {
booB = false;
}
//...
Mine, from last week :-)
Just came across this today, reminds me of Steven Wenrich's example above.
function tab1Function() {
clearTabs();
gotoAndStop('frmHeadgear');
}
///
function tab2Function() {
clearTabs();
gotoAndStop('frmEye');
}
///
function tab3Function() {
clearTabs();
gotoAndStop('frmAccessories');
}
///
function tab4Function() {
clearTabs();
gotoAndStop('frmActivities');
}
// IT JUST GOES ON LIKE THIS
The purpose of the application was to report weekly sales for each facility, aggregated to 3 intermediate organizational levels and then organization wide.
They started by retrieving all transaction records for the week for the whole organization. Cause you know databases are good for storing data but you wouldn't want to process any with one.
They then looped through all the records to calculate the aggregate values for the whole organization. Then they looped through all the records again for each organizational unit at each level, finally looping through for each facility. They processed every record over 100 times.
And they weren't calling any subroutines in any of the loops, it was all inline code. And as they aggregated the data they stored it in arrays with each array element representing a field of the record. And they weren't even consistent about which array element represented which field.
This horrendous code is undoubtedly WYSIWYG related, however worth the mention for the chuckle. Note, it's only HTML. The moral is, if you do use WYSIWYG editors, run a clean-up afterwards! To the code!
1) Visit http://www.fujinonbinos.com/
2) View Source
3) Enjoy all the tags. It's like an animated pattern as you scroll down :s
Clayton: Actually there is some who think this was done on purpose. Check this story. http://b3ta.com/links/355881
if(OK1)
if(OK2)
if (OK3)
if(OK4)
else(ERR4)
if()
else()
else(ERR3)
else(ERR2)
else(ERR1)
And that cascade of if went as deep as 11 levels in pretty much 80% of all methods...
@Clayton...
AWESOME
I am going to make sure all HTML I write from now on generates a huge ascii image in the source! :D
BRUTAL CYCLE:
var i = 0;
while(true) {
try {
trace(arr[i]);
// do something to arr[i]
} catch (e:RangeError) {
break;
}
++i;
}