Worst coding ever - what to do?

  • Thread starter Thread starter Borg
  • Start date Start date
  • Tags Tags
    Coding
AI Thread Summary
The discussion revolves around the challenges faced while working on a poorly structured Java programming assignment. The code is described as excessively lengthy and convoluted, with one method exceeding 2,500 lines and numerous instances of copy-pasting leading to redundancy. The programmer is attempting to refactor the code by creating List objects to simplify variable management and reduce the number of methods. Despite the frustration, there is a focus on improving the code quality for the customer, who appreciates the efforts. The programmer shares experiences of breaking down the code into more manageable classes and finding additional issues that clarify previous customer frustrations. There is a sense of camaraderie among peers, with suggestions to document the experience for future reference and even submit the code to humor sites like The Daily WTF. Ultimately, the project is nearing completion, with the customer expressing satisfaction with the improvements made.
Borg
Science Advisor
Gold Member
Messages
2,268
Reaction score
4,872
I am currently in the middle of a three month Java programming assignment, working on the worst code I ever thought to see. It looks like it was written by a monkey who was being rewarded by hitting a giant button marked "Copy and Paste". One class file that I'm working on has over 10,000 lines of code with one method that is over 2,500 lines long!

That file is generally manipulating 11 sets of variables but, they chose to create individually named variables like entry1, entry2, entry3, etc. Because of this, they have numerous methods like processEntry1, processEntry2, etc. where the code in each of these methods is copied and pasted from the others with just the numbers changed. To top this off, they often have helper methods for these methods that go back to the database to retrieve data that they've already retrieved in the calling method. It almost looks like a deliberate attempt to slow the entire system to a crawl.

I've been trying to condense it down to something readable by creating List objects of the variables so that I can create single instances of these processEntry type methods. However, I've created 31 lists of variables already and still haven't gotten them all. In addition, there are public getEntry1 and setEntry1 type methods for every one of the variables (11 * 31 * 2 - 682 getters and setters and counting). This is just one of the files in a project that has the same programming style everywhere. It reminds me of the old game of Zork - You are in a maze of twisty passages, all alike... :rolleyes:

I'm trying to do the best for the customer but, I'm getting to the point where it just isn't worth it. I have a list of bugs that they want fixed but, many of them are due to hard to track down copy and paste errors. By cleaning the code, I often fix the bugs. The question that I have is what would you do? Would you just slog it out or fix what you can and pray that the repair contract doesn't get extended?
 
Technology news on Phys.org
I would ask them for the original program specification, then ask them if they want me to re-write the program. That sounds easier than what your having to do.
 
I interned for a year at a software engineering firm. I have yet to see readable, nice, non-redundant code.

My job turned into what you are doing now, which is why I quit. Sometimes something you love to do as a hobby isn't the best choice for a job.

I suggest you power through it if you really like designing/writing computer programs/web applications/what not, and you want to do it for a career. It will pay off in the end, for sure.

But if you were like me and it was just kind of a 'hobby', then give it some thought.

I still write code, and I still love it. I just love seeing my own code.
 
Yesterday, I finally got enough variables reorganized to tackle the 2500 line method. After I had rewritten it, it was only 90 lines of code - two nested loops doing the same thing over and over.

I know that I will slog it out. I mostly just needed to vent after 7 weeks of rewriting. I actually like programming and the company that I work for. It just amazes me though how bad software can get sometimes. I do have a better project waiting for me in January that will be all new code that I will have a hand in designing, so I will look forward to that.
 
> Yesterday, I finally got enough variables reorganized to tackle the 2500 line method. After I had rewritten it, it was only 90 lines of code - two nested loops doing the same thing over and over.

That sounds scary. If they can be that bad, presumably the rest of it is just as amateur.
 
Borg said:
Yesterday, I finally got enough variables reorganized to tackle the 2500 line method. After I had rewritten it, it was only 90 lines of code - two nested loops doing the same thing over and over.

Contact Guinness Book of Records, perhaps they keep track of such cases.
 
You beat me to it David
 
silverfrost said:
> Yesterday, I finally got enough variables reorganized to tackle the 2500 line method. After I had rewritten it, it was only 90 lines of code - two nested loops doing the same thing over and over.

That sounds scary. If they can be that bad, presumably the rest of it is just as amateur.

It is.

DavidSnider said:
Submit it to The Daily WTF

http://thedailywtf.com/Default.aspx

Nice link. Thanks. I may submit it when I get the time.
 
  • #10
Your post made me smile. Sorry about that. Might I suggest that you archive a copy of this crap in case you ever get to teach programming. And awful as it is, this kind of disgust has helped reform some of my own tendency towards laziness. But code that smells that bad--I'd leave the job unless I were hungry enough.
 
  • #11
P S - It's a rare client or manager who will let you rewrite what needs to be rewritten. Unless they are themselves programmers and have been through it, it's very difficult to get them to understand the issues.

Good luck with that.
 
  • #12
harborsparrow said:
P S - It's a rare client or manager who will let you rewrite what needs to be rewritten. Unless they are themselves programmers and have been through it, it's very difficult to get them to understand the issues.

Good luck with that.

The customer has already expressed pleasure that I'm working on the code so, yes, I'm fortunate in that respect. I haven't told them how extensively I've been cleaning the code though. :wink:

BTW, the code has now been broken down into two classes that are each 1000 lines long - still longer than I would like. All of the variables, getters and setters are in one class and the business logic is in another. Much easier to see what it does. I've already found several more issues that explain other frustrations that the customer had, so that should further justify what I've been doing.
 
  • #13
I just noticed that I've been listening to a song entitled "Search and Destroy". How appropriate. :-p
 
  • #14
This code just gets better all the time. Now that I've cleaned it up, I found yet another set of bizarre coding hoops. One page has up to 11 tables being displayed with results from a search. Each table alternates in color (yellow, blue, yellow, blue, etc.). The coder wrote a set of variables along with their getters and setters to track the data in each of the tables - dataSet1, getDataSet1, setDataSet1, dataSet2, getDataSet2, setDataSet2, etc.

This is bad enough but they decided to take it a step further. They also created another set of variables with names like dataSet11, getDataSet11, setDataSet11, dataSet21, getDataSet21, setDataSet21, etc. Why? So that they could store the yellow records in the first set and the blue records in the second set. They then had a whole pile of convoluted logic on the server side that was trying to guess where they had put the data. How can someone be so dumb? :smile: :smile: :smile: :smile: :smile:
 
  • #15
DavidSnider said:
Submit it to The Daily WTF

http://thedailywtf.com/Default.aspx

I submitted it today. I'll update this if it gets posted.

I also decided to just add blog entries for any other gems that I may find. Today's had me on the floor laughing.
 
  • #16
Borg said:
How can someone be so dumb? :smile: :smile: :smile: :smile: :smile:

Try not to be too hard on em. Every day I check that site I expect to see snippets from my intern days. :smile:
 
  • #17
> Today's had me on the floor laughing.

A big step up from crying :)
 
  • #18
Coding that bad is actually rather impressive. There should be an award for things like that.
 
  • #19
DavidSnider said:
Submit it to The Daily WTF

http://thedailywtf.com/Default.aspx

Borg said:
I submitted it today. I'll update this if it gets posted.

They finally printed it. http://thedailywtf.com/Articles/The-Integer-Cache.aspx" in the comments section for anyone who's interested.

We've fixed all of the serious problems and the customer is extremely happy. I am so glad that this project is almost finished. I was afraid that some of it might rub off...
 
Last edited by a moderator:
  • #20
Congratulations all round by the sound of it.
 
  • #21
Borg said:
They finally printed it. http://thedailywtf.com/Articles/The-Integer-Cache.aspx" in the comments section for anyone who's interested.

We've fixed all of the serious problems and the customer is extremely happy. I am so glad that this project is almost finished. I was afraid that some of it might rub off...
Oh that was you? I just found this thread today, I thought it sounded familiar! :smile:

Congratulations, by the way.
 
Last edited by a moderator:

Similar threads

Back
Top