Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Worst coding ever - what to do?

  1. Nov 7, 2009 #1

    Borg

    User Avatar
    Gold Member

    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. :yuck: 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?
     
  2. jcsd
  3. Nov 7, 2009 #2

    madmike159

    User Avatar
    Gold Member

    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.
     
  4. Nov 7, 2009 #3

    whs

    User Avatar

    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.
     
  5. Nov 8, 2009 #4

    Borg

    User Avatar
    Gold Member

    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.
     
  6. Nov 9, 2009 #5
    > 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.
     
  7. Nov 9, 2009 #6

    Borek

    User Avatar

    Staff: Mentor

    Contact Guinness Book of Records, perhaps they keep track of such cases.
     
  8. Nov 9, 2009 #7

    DavidSnider

    User Avatar
    Gold Member

  9. Nov 9, 2009 #8
    You beat me to it David
     
  10. Nov 10, 2009 #9

    Borg

    User Avatar
    Gold Member

    It is.

    Nice link. Thanks. I may submit it when I get the time.
     
  11. Nov 10, 2009 #10

    harborsparrow

    User Avatar
    Gold Member

    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.
     
  12. Nov 10, 2009 #11

    harborsparrow

    User Avatar
    Gold Member

    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.
     
  13. Nov 11, 2009 #12

    Borg

    User Avatar
    Gold Member

    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.
     
  14. Nov 11, 2009 #13

    Borg

    User Avatar
    Gold Member

    I just noticed that I've been listening to a song entitled "Search and Destroy". How appropriate. :tongue:
     
  15. Nov 13, 2009 #14

    Borg

    User Avatar
    Gold Member

    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? :rofl: :rofl: :rofl: :rofl: :rofl:
     
  16. Nov 17, 2009 #15

    Borg

    User Avatar
    Gold Member

    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.
     
  17. Nov 17, 2009 #16

    DavidSnider

    User Avatar
    Gold Member

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

    A big step up from crying :)
     
  19. Nov 19, 2009 #18
    Coding that bad is actually rather impressive. There should be an award for things like that.
     
  20. Jan 4, 2010 #19

    Borg

    User Avatar
    Gold Member

    They finally printed it. http://thedailywtf.com/Articles/The-Integer-Cache.aspx" [Broken] 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... :yuck:
     
    Last edited by a moderator: May 4, 2017
  21. Jan 4, 2010 #20
    Congratulations all round by the sound of it.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Worst coding ever - what to do?
Loading...