Worst coding ever - what to do?


by Borg
Tags: coding
Borg
Borg is online now
#1
Nov7-09, 06:19 AM
PF Gold
Borg's Avatar
P: 728
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...

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?
Phys.Org News Partner Science news on Phys.org
Simplicity is key to co-operative robots
Chemical vapor deposition used to grow atomic layer materials on top of each other
Earliest ancestor of land herbivores discovered
madmike159
madmike159 is offline
#2
Nov7-09, 08:24 AM
PF Gold
madmike159's Avatar
P: 370
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.
whs
whs is offline
#3
Nov7-09, 10:38 PM
P: 85
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.

Borg
Borg is online now
#4
Nov8-09, 04:28 AM
PF Gold
Borg's Avatar
P: 728

Worst coding ever - what to do?


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.
silverfrost
silverfrost is offline
#5
Nov9-09, 06:52 AM
P: 43
> 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.
Borek
Borek is offline
#6
Nov9-09, 07:31 AM
Admin
Borek's Avatar
P: 22,659
Quote Quote by Borg View Post
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.
DavidSnider
DavidSnider is offline
#7
Nov9-09, 08:40 AM
PF Gold
P: 430
Submit it to The Daily WTF

http://thedailywtf.com/Default.aspx
silverfrost
silverfrost is offline
#8
Nov9-09, 09:01 AM
P: 43
You beat me to it David
Borg
Borg is online now
#9
Nov10-09, 03:57 AM
PF Gold
Borg's Avatar
P: 728
Quote Quote by silverfrost View Post
> 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.

Quote Quote by DavidSnider View Post
Submit it to The Daily WTF

http://thedailywtf.com/Default.aspx
Nice link. Thanks. I may submit it when I get the time.
harborsparrow
harborsparrow is offline
#10
Nov10-09, 09:53 PM
harborsparrow's Avatar
P: 322
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.
harborsparrow
harborsparrow is offline
#11
Nov10-09, 09:54 PM
harborsparrow's Avatar
P: 322
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.
Borg
Borg is online now
#12
Nov11-09, 04:15 AM
PF Gold
Borg's Avatar
P: 728
Quote Quote by harborsparrow View Post
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.

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.
Borg
Borg is online now
#13
Nov11-09, 04:18 AM
PF Gold
Borg's Avatar
P: 728
I just noticed that I've been listening to a song entitled "Search and Destroy". How appropriate.
Borg
Borg is online now
#14
Nov13-09, 01:10 PM
PF Gold
Borg's Avatar
P: 728
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?
Borg
Borg is online now
#15
Nov17-09, 11:39 AM
PF Gold
Borg's Avatar
P: 728
Quote Quote by DavidSnider View Post
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.
DavidSnider
DavidSnider is offline
#16
Nov17-09, 11:49 AM
PF Gold
P: 430
Quote Quote by Borg View Post
How can someone be so dumb?
Try not to be too hard on em. Every day I check that site I expect to see snippets from my intern days.
silverfrost
silverfrost is offline
#17
Nov17-09, 12:47 PM
P: 43
> Today's had me on the floor laughing.

A big step up from crying :)
Lancelot59
Lancelot59 is offline
#18
Nov19-09, 10:42 AM
Lancelot59's Avatar
P: 668
Coding that bad is actually rather impressive. There should be an award for things like that.


Register to reply

Related Discussions
Need help coding with TI-89. Int{sin(x),x,0,inf} Calculators 6
computer coding Programming & Computer Science 8
Coding and GF(2) Set Theory, Logic, Probability, Statistics 1
Need PHP coding help Computing & Technology 4
Coding Theory Set Theory, Logic, Probability, Statistics 4