Slashdot Mirror


How To Deal With 200k Lines of Spaghetti Code

An anonymous reader writes "An article at Ars recaps a discussion from Stack Exchange about a software engineer who had the misfortune to inherit 200k lines of 'spaghetti code' cobbled together over the course of 10-20 years. A lengthy and detailed response walks through how best to proceed at development triage in the face of limited time and developer-power. From the article: 'Rigidity is (often) good. This is a controversial opinion, as rigidity is often seen as a force working against you. It's true for some phases of some projects. But once you see it as a structural support, a framework that takes away the guesswork, it greatly reduces the amount of wasted time and effort. Make it work for you, not against you. Rigidity = Process / Procedure. Software development needs good processes and procedures for exactly the same reasons that chemical plants or factories have manuals, procedures, drills, and emergency guidelines: preventing bad outcomes, increasing predictability, maximizing productivity... Rigidity comes in moderation, though!'"

160 of 236 comments (clear)

  1. ...no by Anonymous Coward · · Score: 4, Funny

    no comment...

    1. Re:...no by wmac1 · · Score: 3, Interesting

      In several iterations, disentangle and break the code into smaller and more understandable chunks.

      After breaking the code into smaller chunks clean them up (code conventions, algorithms, ...) and reorganize as needed.

    2. Re:...no by DJRumpy · · Score: 4, Insightful

      I disagree. For 200K lines of code, You immediately start a new project to produce the next major release of said code.

      200,000 lines of code is a large project, but very do-able for even with a small team or one person. Although you could go in an attempt to tighten up code in smaller chunks, the very fact that this code was written over the course of many years, probably by many authors and styles, means it probably follows no standard to general layout, declarations, etc. (hence the spaghetti).

      I would simply support what's there with only a break-fix policy, and immediately start documenting all aspects of it's functionality to rebuild it from the bottom up. The very fact that this code would have so many styles would mean most of it would have to be re-written and documented anyway.

      Document the functionality, re-implement with standard code to guidelines, include any feature enhancements that may exist, release new version.

    3. Re:...no by Stormthirst · · Score: 1

      What's more, there may well be libraries to do some of the functionality. According to the article, it's written in G2 which is all but obsolete. Find a modern language that more closely matches G2's functionality and move to that.

    4. Re:...no by kestasjk · · Score: 2

      It depends what sort of thing it is, how complex it is, whether the software is the kind of thing that can be tested easily or if the rules are embedded in the spaghetti, etc, etc.

      One person given 200KLOC of complex spaghetti to rewrite though, if with little documentation outside of the code, and software that doesn't lend itself to automated testing, where the spaghetti logic is of consequence to the business.. that could be a very, very long project (years, easily).

      --
      // MD_Update(&m,buf,j);
    5. Re:...no by eugene+ts+wong · · Score: 1

      Hi. What is a "break-fix policy"? I skimmed through the first page of Google's results, and Wikipedia had nothing.

    6. Re:...no by Rockoon · · Score: 3, Insightful

      Isnt this how Netscape died?

      --
      "His name was James Damore."
    7. Re:...no by DJRumpy · · Score: 2

      Yes and no. Part of the complexity of a new program is missing here. The full functionality is mapped out, albeit they will have to have to glean some functionality from the code and most from the end users. That's a huge boon as long as the end users can effectively comminicate or demonstrate that functionality.

      In short, the map is already written and scope creep can be largely minimized with some proper expectations and management.

    8. Re:...no by DJRumpy · · Score: 4, Informative

      A break-fix policy is simply stating you will support code to fix any breaks in functionality, while denying any enhancement requests. In short, the only changes you make to the old code would be to fix production issues.

      It lets you focus efforts on implementing new code while avoiding supporting enhancements on the old code.

    9. Re:...no by Anonymous Coward · · Score: 1

      Netscape failed because they failed to get the open source community to commit to the project, and management failed to set proper guidelines ( the rigidity mentioned in TFA).

      You have to have proper expectations, milestones, a project map. You can't 'wing' these things, which is similar to the rigidity TFA mentions.

      In this case, they have a controlled group of actively engaged people who are interested in doing things the 'right' way, rather than 50 different voices all claiming they know the right way. It makes a huge difference.

    10. Re:...no by AF_Cheddar_Head · · Score: 1

      I would guess 10-20 years.

    11. Re:...no by eugene+ts+wong · · Score: 2

      That's a great policy to have. I wish that Linux distros and various apps were developed like that. I only upgrade for the bug fixes and the security fixes.

    12. Re:...no by DJRumpy · · Score: 1

      I'm fortunate to have an environment where upper management understands and supports that sometimes deprecating a codebase is more desirable than supporting two code bases in parallel. It can take a LOT of pressure off of a development team to allow them to focus properly on the task at hand. All code eventually gets 'dirty' as it ages. A clean slate with an eye for the big picture (hindsight) can prove invaluable for supportability.

      In my opinion, when you are spending more time trying to make code work within the existing framework than just adding enhancements, it's time to evaluate a major release.

    13. Re:...no by frosty_tsm · · Score: 1

      There are certain advantages to doing the re-write that speed it up. Libraries and frameworks can make a project that used to be 200k of lines to 20-50k of lines. You also have the existing code as a reference, use it. Create tests that pass against the old code to verify the new code (note when they find bugs in the old code, but be careful that others might be depending on said bugs).

      Sometimes the code in question is too broken to keep and refactor; you just need to burn it.

    14. Re:...no by ralphdaugherty · · Score: 4, Informative

      G2 is being called virtually obsolete. I looked up G2 in Wilipedia comparison of programming languages http://en.wikipedia.org/wiki/Comparison_of_programming_languages and it is listed as:

      Language: G2
      Intended use: Application, inference, expert system
      Paradigms: common graphical development and runtime environment, event-driven, imperative, object-oriented

      Plus the search on G2 shows there is a G2++. So what does obsolete mean to those calling it obsolete?

      btw, I'm an RPG programmer and I've been writing tons of new business software every day for the last 23 years, the whole time the language has been declared obsolete.

      Now get off my lawn.

    15. Re:...no by turbidostato · · Score: 1

      "I wish that Linux distros and various apps were developed like that."

      Like Debian Stable, you mean?

    16. Re:...no by eugene+ts+wong · · Score: 1

      I don't know. I'd have to look carefully. I'm under the impression that Debian Stable is quite old, and that the desktops that are available are also quite old. I don't know enough about Debian to comment.

    17. Re:...no by crankyspice · · Score: 3, Informative

      Isnt this how Netscape died?

      According to Joel Spolsky...

      --
      geek. lawyer.
    18. Re:...no by turbidostato · · Score: 1

      "I don't know enough about Debian to comment."

      But still you *do* comment. You said "I wish that Linux distros and various apps were developed like that" (adding just security updates to otherwise stable software), when it's obvious you didn't take the time to learn if that's already the case or not.

    19. Re:...no by eugene+ts+wong · · Score: 1

      It depends on what the new features are, and where, but you're right. Some things just don't need updating, until further down the line.

    20. Re:...no by styrotech · · Score: 1

      So you want a distro that only does bug fixes and security fixes, but doesn't end up with old software? How does that work?

    21. Re:...no by hairyfeet · · Score: 1

      Don't forget all those different programmers means differing levels of skill so some of its gonna be nice and simple, some of it is gonna be be an ugly hack. Trying to fix all that without a plan would just be nuts, better to slowly document what every piece does and once you have a better idea of what is going where and doing whatever, THEN you can choose whether to fix or build anew.

      --
      ACs don't waste your time replying, your posts are never seen by me.
    22. Re:...no by eugene+ts+wong · · Score: 1

      I don't mean that everything on the system is only upgraded for security fixes and and bug fixes. I meant that only the base system is upgraded that way.

      I was trying to explain through these comments, that we really don't need a super old copy of a word processing software package, or some such thing. If that's unstable, then it shouldn't be as big a deal, than if the entire base were unstable. It's important to update those apps that people really think about, because it affects productivity.

      As a couple of specific examples, I want to update this web browser A.S.A.P., because the spellcheck is broken [Opera 12.01 or whatever is the latest], and because Opera might be missing critical features, whereas, with the base system, I don't need new features. For word processors, I might need a feature, like exporting to PDF, so I am willing to upgrade, as long as it works.

      For something like a desktop environment, I don't want bug fixes and security fixes to be mixed in with the new features. I want the fixes to be taken care of, and then when the DE is stable, we can focus on new features. Or maybe the new features can be part of the next version.

      Do you know what I mean?

    23. Re:...no by eugene+ts+wong · · Score: 1

      Fair enough. Thanks for the correction.

      Do you use Debian Stable?

    24. Re:...no by jhol13 · · Score: 1

      I'd do completely opposite.

      I'd drop the old code 99-100%. Start from top to bottom, document everything and perhaps even use some other, modern, programming language.
      The resulting code base is almost certainly lot less than 100k lines (+ comments & documentation, depends how you calculate these).

    25. Re:...no by fluffy99 · · Score: 1

      G2 is being called virtually obsolete. I looked up G2 in Wilipedia comparison of programming languages http://en.wikipedia.org/wiki/Comparison_of_programming_languages and it is listed as:

      Language: G2
      Intended use: Application, inference, expert system
      Paradigms: common graphical development and runtime environment, event-driven, imperative, object-oriented

      Plus the search on G2 shows there is a G2++. So what does obsolete mean to those calling it obsolete?

      btw, I'm an RPG programmer and I've been writing tons of new business software every day for the last 23 years, the whole time the language has been declared obsolete.

      Now get off my lawn.

      So basically similar to LabView? I'd be inclined to re-write this all in LabView rather than try to rewrite this all in traditional software programming.

    26. Re:...no by johnw · · Score: 1

      I don't know. I'd have to look carefully. I'm under the impression that Debian Stable is quite old, and that the desktops that are available are also quite old.

      Errr, well, yes... that's what you asked for. You can't have it both ways. If you specify that you want only bug-fixes and not new functionality, you can't then complain when you get just bug fixes and no new functionality.

      The current Debian Stable (Squeeze) is a very capable distribution, and whilst it doesn't have the very latest versions of Gnome and KDE (as per your specification) they are more than modern enough for everyday use.

    27. Re:...no by Eraesr · · Score: 1

      There's a good chance that functionality hidden in those 200K lines of code can be rewritten in half that much code. Such spaghetti projects tend to bloat in amount of code as time progresses and multiple coders are working on it.

    28. Re:...no by turbidostato · · Score: 1

      "Do you use Debian Stable?"

      Yes. The desktop I'm using right now is a Debian Stable.

    29. Re:...no by LizardKing · · Score: 1

      In several iterations, disentangle and break the code into smaller and more understandable chunks.

      After breaking the code into smaller chunks clean them up (code conventions, algorithms, ...) and reorganize as needed.

      Depending on the language and the quality of the codebase, this may not be possible. For example, I've worked on a project with 1,000,000+ LOC that defied all attempts to refactor it. This was in C++, which offers a number of features that can help reduce the coupling between code, but in practice the lack of encapsulation meant any refactoring attempt failed. The only answer was a ground up rewrite with a better up front design and thorough code reviews.

    30. Re:...no by Slashdot+Parent · · Score: 1

      I would simply support what's there with only a break-fix policy, and immediately start documenting all aspects of it's functionality to rebuild it from the bottom up. The very fact that this code would have so many styles would mean most of it would have to be re-written and documented anyway.

      Do you have a PhD in chemistry and 20 years' experience in the application's domain? If not, then you are unqualified rewrite or even test this application.

      That's the problem. There's 20 years' worth of knowledge locked up in those 200k lines of code. Scrapping it would be a royally bad idea. Chipping away at it a bit at a time is a much better plan.

      --
      They don't grade fathers, but if your daughter's a stripper, you fucked up. --Chris Rock
    31. Re:...no by robertinventor · · Score: 1

      Depends, if e.g. it is a super efficient fast fourier transform that has been honed to perfection over years, and is as fast as the programmer can make it, but is poorly documented, and doesn't need to be changed, you don't want to refactor that even if you don't understand in detail how it works. Or if it is some very specialist code that requires advanced understanding of high level maths or physics to understand. There are things that researchers might program that a programmer without specialist understanding of their field might find hard to reproduce, depending on the field and whether the researchers have a natural talent for programming. But if it is spaghetti code that just does stuff that is bread and butter programming, re-implementing a search and replace say, or a binary tree, or handling gui input and pre-parsing it for the meat of the program, or things like that, then it's best to refactor it if you can.

  2. Farm out OP writing, too. by Impy+the+Impiuos+Imp · · Score: 1

    I advise rigidly farming it out.

    --
    (-1: Post disagrees with my already-settled worldview) is not a valid mod option.
    1. Re:Farm out OP writing, too. by symbolset · · Score: 3, Interesting

      I advise printing it out and posting it in the hall in printed form, annotated with contributors. Paper the walls with it. You would be surprised how much more efficient that makes a coder even if it's not ever read.

      Also, for debugging sometimes you have to get down on the floor with 50 pages of fanfold and work it out. Decorum be damned. A PC only has so much vertical resolution and sometimes you need more than to peek at the code through a sliding window.

      --
      Help stamp out iliturcy.
    2. Re:Farm out OP writing, too. by h4nk · · Score: 1
      I have totally done this. I use hightlighter markers to identify chunks of purpose/responsibility/function per file and then set to refactoring with UML and CRC cards. Usually it's a complete rewrite, but you may be able to make slight refactorings and iterate over the code as releases go out.

      read this book:
      http://www.amazon.com/Refactoring-Improving-Design-Existing-Code/dp/0201485672

      CRC cards:
      http://en.wikipedia.org/wiki/Class-responsibility-collaboration_card

    3. Re:Farm out OP writing, too. by Sulphur · · Score: 2

      I advise printing it out and posting it in the hall in printed form, annotated with contributors. Paper the walls with it. You would be surprised how much more efficient that makes a coder even if it's not ever read.

      Also, for debugging sometimes you have to get down on the floor with 50 pages of fanfold and work it out. Decorum be damned. A PC only has so much vertical resolution and sometimes you need more than to peek at the code through a sliding window.

      You can also flip through fanfold like a book and see two pages at a time with an option to turn several pages at once.

    4. Re:Farm out OP writing, too. by __aaltlg1547 · · Score: 1

      I used to do this back in the day, but it's a long time since I've seen fanfold paper, let alone the wide greenbar paper I prefer. Where does one get fanfold paper and a printer that can handle it these days?

    5. Re:Farm out OP writing, too. by Grishnakh · · Score: 1

      I was about to ask the same question. The only places I even see those old dot-matrix printers these days is at banks, and they appear to be using the exact same printers they were using 25 years ago.

    6. Re:Farm out OP writing, too. by Grishnakh · · Score: 1

      I googled those things some time ago, maybe a few years ago, perhaps on Newegg, and was surprised to see them still being sold (though again, I've never seen one sold in a local store, I think it's online-only). But what surprised me even more was that it looked like they were exactly the same as they were around 1990. I mean they were identical: the cabinets, the control buttons; the designs hadn't changed one bit since then. They looked really odd compared to the aesthetics of modern computer equipment.

    7. Re:Farm out OP writing, too. by gmhowell · · Score: 1

      eBay.

      I know the last time I had to buy any was about eight years ago. The narrow carriage models for 8.5x11 were still being sold by Okidata. Our wide carriage for greenbar were still kicking along. I had one saved for a while that we no longer needed, but I think it got tossed following a divorce :(

      --
      Jesus was all right but his disciples were thick and ordinary. -John Lennon
  3. "Cobbled together over 10-20 years . . . ?" by PolygamousRanchKid+ · · Score: 5, Insightful

    Wouldn't that be Linux? It seems to work fine for me.

    If something has become spaghetti over 10-20 years, then no one cared that it became spaghetti over 10-20 years. And it will still be spaghetti over the next 10-20 years. Fixing something like this requires a commitment from management, which means money. If the management of the project aren't convinced that cleaning up the development process is worth the initial investment for the long term, then they choose to deal with the constantly higher costs forever.

    Something like this makes me think that this is one of those problems that get pushed off for someone else to deal with later. And the next person perpetuates this, by doing the same.

    --
    Schroedinger's Brexit: The UK is both in and out of the EU at the same time!
    1. Re:"Cobbled together over 10-20 years . . . ?" by sourcerror · · Score: 1, Insightful

      The really frightening tought is that there are many 40 year old first year CS students.

    2. Re:"Cobbled together over 10-20 years . . . ?" by Anonymous Coward · · Score: 1

      Usually because of budgets. I love the courses in college that tell you how you should do something to make maintenance easier but then ignore the real world contraint of time and money (probably the most underrepresented part of making software). Making something with care takes more time (and therefore money) thank hacking something together. Sometimes a lot more, but always at least a noticeable amount. And rewriting 200k lines of code, no matter how you do it (refactoring or complete rewrite from the ground up) is not going to be cheap. Unless the current program directly and obviously causes a perfect shitstorm, that's just not likely to happen. Sure keeping it increases cost every quarter, but even if you could accurately quantify the increased cost for this, it won't be as much in any quarter or year as fixing the entire problem, and while fixing the problem NONE of that budget is actually adding new end user features. So under most conditions you are asking for something that the users of the software won't even be able to see when you finish, and managers will only be able to see several months after you finish, and only if they look back AND can accurately figure out how much faster you were able to add new features and how much less time you spent fixing problems.

    3. Re:"Cobbled together over 10-20 years . . . ?" by gl4ss · · Score: 3, Insightful

      would fixing it to not be spaghetti be any better though? would fixing it to be really non-confusing depend on changing real world processes of clerks etc?

      spaghetti turned into OO is going to be spaghetti too, just with a lot more of sauce and different bits which look almost the same but turn out to be tomato or minced meat upon closer inspection and when you take plunge into the platter and eat something you don't really know what you ate or how it got there, what I'm trying to get at is that if it's spaghetti because of already re-using lots of the code in lots of places then the rewrite could end up being 2 million lines (commercial rewrites of sw for gov. have a habit of ending up like this..).

      at least he can probably feel good about it not being knights capital trading system.

      but he's asking how to deal with it, with good development tools(that have good find/locate) and good memory. start exploring what the sw really does and guessing where you might be asked to do modifications.

      --
      world was created 5 seconds before this post as it is.
    4. Re:"Cobbled together over 10-20 years . . . ?" by AmberBlackCat · · Score: 1

      I think, at least for open source projects, making the code easy to follow would bring in a lot of help from people who are good at writing code but don't want to spend years trying to figure out how to pick up where somebody left off in a pile of obfuscated goo.

    5. Re:"Cobbled together over 10-20 years . . . ?" by Anonymous Coward · · Score: 3, Insightful

      When I was taking my 2nd degree in Computer Science years ago, there was quite a few mature students. They are actually doing well in class in spite of other distractions in life such as family.

      There was nothing wrong with people deciding to learn new things or switch career later in life. Are you biased or just like to discriminate people for their age?

      I would think that matured people are more suited for computer science as they are not as much distracted by the new "Shiny" new thing that comes along and constantly have to redo things not because they don't work, but they are not the "latest and greatest".

    6. Re:"Cobbled together over 10-20 years . . . ?" by Anonymous Coward · · Score: 1

      I think that wasn't meant literally. It's more like that there are many 40 year old who still write code as if they were 1st year CS students.

    7. Re:"Cobbled together over 10-20 years . . . ?" by evil_aaronm · · Score: 1

      I agree with you, to an extent. I inherited a monstrosity, as well - twice, in fact - and each time it was, "I can fix this so that it's easier to maintain," and the first manager said, "But that means we'll have to test it even more to find any newly introduced bugs." The second said, "Your proposal is too complex; make it the way it was," even though almost no one but me could figure it out in the first place. The second manager, however, was the type of guy who would cut and paste a block 10 ten times, changing a single parameter for each block, rather than just build a loop around the code block. As such, his "It's too complex," was a reflection on his inability to understand abstractions, and we generally fear that which we don't understand. I don't work for that dickhead anymore, and I'm so thankful. Unfortunately, he's still managing a medical device that impacts peoples' lives, and his code is still shit.

    8. Re:"Cobbled together over 10-20 years . . . ?" by Sulphur · · Score: 1

      Are you biased or just like to discriminate people for their age?

      He's probably American - ergo bias and discrimination are his first amendment rights - along with racism, sexism. Etc. It's the curse of the first amendment - they're thinking is stuck in the 17th century.

      Our former mayor was fond of saying that "people don't suffer in silence."

    9. Re:"Cobbled together over 10-20 years . . . ?" by assertation · · Score: 1

      All true

      I would add that one of the disappointing things about programming is that few people ever see let alone appreciate a job well done.

      If the application works or even works "good enough", nobody cares if the coding is done well.......they don't even care to look at it.

    10. Re:"Cobbled together over 10-20 years . . . ?" by Grishnakh · · Score: 1

      I love the courses in college that tell you how you should do something to make maintenance easier but then ignore the real world contraint of time and money (probably the most underrepresented part of making software). Making something with care takes more time (and therefore money) thank hacking something together.

      Sorry, but the college courses are correct; hacking something together poorly will cause you to have higher long-term costs. CS departments can't help it if the morons over in the Business Schools across campus are teaching all the MBAs to be short-sighted idiots.

    11. Re:"Cobbled together over 10-20 years . . . ?" by Hognoxious · · Score: 1

      What discount rate are you applying?

      --
      Confucius say, "Find worm in apple - bad. Find half a worm - worse."
    12. Re:"Cobbled together over 10-20 years . . . ?" by sourcerror · · Score: 1

      I obviously didn't mean that. The linked Stackoverflow post speaks about senior scientists with no software engineering knowledge at all have written this big ball of spaghetti. Some people have 20 years of coding experience. Others have 20 times one year experience.

  4. Easy! by blackicye · · Score: 4, Funny

    Outsource it to India!

    1. Re:Easy! by Sponge+Bath · · Score: 1

      You can spot Welsh from a mile away :P

      When I could not find "cewch eich cod" in my Klingon dictionary, I assumed he was just posting while drunk.

    2. Re:Easy! by mrmeval · · Score: 2

      Huh, they're getting to be as expensive as in-house development with just as sloppy code depending on which business you go to. There is also a substantial language barrier in some cases even though there are a lot who do speak English they do not comprehend some concepts. You then need a liaison who does and can translate your requests. That adds cost. We did find a very good software development company that is prompt, competent and who worked to understand our needs. We do save money but it's not nearly as much as it used to be. The costs won't go too high as India's success has several countries catching up to them.

      --
      I'd go on a Vegan diet but the delivery time from Vega is too long. --brownkitty
    3. Re:Easy! by rbrausse · · Score: 1

      Welsh

      while drunk

      this is synonym, isn't it?

  5. Rewrite it by ddt · · Score: 1

    Rewrite it from scratch using the spaghetti code version to run correctness tests to verify you haven't changed the behaviour.

    200k lines is about how large the Doom codebase was, and it wasn't uncommon for John Carmack to rewrite most of his game engine in a couple of weeks, a week, or even a weekend when he felt it wasn't going on a good path.

    1. Re:Rewrite it by StripedCow · · Score: 4, Insightful

      200k isn't something you're going to rewrite in a couple of weeks. I think the absolute maximum you could get (for one very skilled person) would be about 5k-10k per week. Rewriting would take on the order of half a year.

      --
      If Pandora's box is destined to be opened, *I* want to be the one to open it.
    2. Re:Rewrite it by bosah · · Score: 1

      Probably not true. If its truly cobbled together as described, and therefore a lot of it has been created 'key to disk', then most of it is probably unnecessary code. Replacing it with a rewrite would more than likely require code that is a considerable order of magnitude lighter than 200k (say between 50-100K). I've seen this kind of crap before a few times, and have succesfully replaced with rewrites, and in reasonable time frames. The main key to doing a rewrite succesfully however is NOT to look at, or replicate the code as it is (but just a bit tidier). The best approach is to go through a proper design to functional specification process, just as if it was a new application. Doing it that way you'll probably find far more elegant coding solutions than are currently being used by the 200k mess and these will cut down on coding time. Moreover it will produce better and more maintainable code, more than you ever would through a tidy and document process. If you think about it, documenting what the spaghetti is doing would probably take as much time, if not much longer, than a fresh design/spec process. Basically the time taken to do a good rewrite is very rarely going to be longer than it would be to unpick the mess. Just keep your team very, very small and make sure everyone including your programmers are involved from the first design/spec discussions onwards. Things go much faster, and you get a far better design, if your coders are invested fully in the project.

    3. Re:Rewrite it by Fuzzums · · Score: 1

      "correctness tests to verify you haven't changed the behaviour"

      So apart from rewriting, you will also have to write a lot of unit tests. Depending on the complexity and type of code, that will take a lot of time too.

      I've rewritten 15 year old Fortran code. It has now some the features that were the reason for the rewrite. That wasn't cheap, but now we have software that can be maintained by a lot more people AND it has unit tests :)
      But writing those unit tests required diving into the old code to produce (partial) data sets to test with. That required actually understanding the old code very well.

      It was a lot of work, but worth it: customer is very satisfied with the result.

      --
      Privacy is terrorism.
    4. Re:Rewrite it by TheRaven64 · · Score: 2

      That depends on whether it actually needs to be that complex. Implementing a project that is 200KLoC is not the same as implementing something that is functionally equivalent to an existing codebase that has grown to 200KLoC. If the project is as described, I wouldn't be surprised if it could be implemented in under 20KLoC, possibly less if there are some existing libraries that can be used.

      --
      I am TheRaven on Soylent News
    5. Re:Rewrite it by StripedCow · · Score: 1

      You're right, but that would be speculative. Also, don't forget about possible migration of data from the old to the new system. That may take considerable effort too. And testing (the old system has gone through 10+ years of testing).

      --
      If Pandora's box is destined to be opened, *I* want to be the one to open it.
    6. Re:Rewrite it by TheRaven64 · · Score: 1

      You're right, but that would be speculative

      True, although I've found that attempting to rewrite a system is a good way of determining how complex it really needs to be. In the end, it doesn't matter if you actually use the rewrite, or even if you finish it. Once you've spent a bit of time on it, you have a much better idea of how the original system should have been designed, and that can help refactoring immensely.

      --
      I am TheRaven on Soylent News
    7. Re:Rewrite it by angel'o'sphere · · Score: 1

      Unit tests are not 'rewriteable'.
      A unit test is testing a compilation unit.
      You need high level functional (scenario/story based) tests, to test a rewrite.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
  6. Re:stackexchange. by blackicye · · Score: 3, Informative

    I knew I read this before:
    http://programmers.stackexchange.com/questions/155488/ive-inherited-200k-lines-of-spaghetti-code-what-now

    That article is linked in the first sentence of the summary.

  7. 1. Lose the attitude by Anonymous Coward · · Score: 5, Insightful

    Well step 1 would be to lose the attitude.

    It's code, it may be in an obsolete language, it may be not to the best industry standards, but its code and it's got enough knowledge in it, that nobody wants to throw it away, and they hired you to maintain it.

    Step 2, I don't know why you would define a process before you understand the code you are to apply the process too?
    Seriously, wtf is all the process stuff about, you're the sole programmer, any rules you set are rods to break your back when you first hit a piece of code you have to break the rules.

    Step 3, you serve them. If you want to port it to a more modern maintainable language, choose one that's easy for THEM to transition to. They've got the knowledge that drives the company, not you, you are the cleaner here. If the phone rings your turn off your vacuum and let them do their job, Mr Cleaner. Nobody gives a fork if the cleaner has best industry procedure for cleaning an office.

    Step 4, break it down. tiny bit by tiny bit, port to a new CLEAN structure, bit by bit. They wrote it, they can identify the core stuff.

    Step 5, once you've ported it, along comes an engineer with a code written to the old language and old methods. Again, that's fine, put away the process manual, these are the experts, if that's the language he can communicate to you in, it's fine, you can understand it, you can port it, you can help him speak the modern lingo. Don't quote your processes to him, you're just the cleaner.

    As for this:
    "Software development needs good processes and procedures for exactly the same reasons that chemical plants or factories have manuals"

    That's someone who *implements* things, typically a bolt together module manager. He is not someone who creates *new* things. Because news things don't come with manuals. You don't know the rules of how they work till the problems needed to make them work are solved. One assembles Microsoft IIS blocks, the other works for Google on image processing. Which are you?

    1. Re:1. Lose the attitude by gbjbaanb · · Score: 2, Insightful

      unfortunately, I think most devs (especially the kind to complain about someone else's "crufty" code) will spend months rewriting, refactoring and introducing today's "best practices" like IoC and Dependency Injection and come up with 300kloc of even worse spaghetti code, that now has extra bugs to be fixed too.

      A bit like how a discussion on stack overflow ended up discussed on ArsTechnica for some (probably advertising-related purpose) and now has come to Slashdot for further adoption. 4chan, you're next.

    2. Re:1. Lose the attitude by Anonymous Coward · · Score: 1

      I don't agree with your accusation of hypocrisy here. He made a valid point about the author's position in the organization: the author works for the company and his first responsibility is to make things work, not to "get rid of spaghetti code". Lose the attitude indeed. If you don't agree attack the argument. Attacking his character ends any hope of a productive discussion.

    3. Re:1. Lose the attitude by assertation · · Score: 2

      I don't mean any disrespect, but you seem to imply that "those people" don't know what they are talking about and have a bit of attitude. It seems like your post has a bit of an attitude.

      Those are good techniques you are criticizing.

      You could have brought up the very good point that programmers should ask themselves why the former devs did something a certain way.

    4. Re:1. Lose the attitude by gbjbaanb · · Score: 1

      its too difficult to describe all the bad techniques that get used simply because they're fashionable, but that's what I meant - the kind of devs who read stuff on the web and suddenly think "we must have that too".

      I went for a job interview a while back and when I gave my reply to their question about test-driven development (that it wasn't a magic bullet that fixes all code quality issues) they weren't too impressed. Obviously they'd read something that said it was, and they weren't going to believe anything less, either that or they had the "new toy" bug and were going to use it no matter what.

      I see the same with Agile, IoC, everything. Besides, after you've got a bit of experience, you can tell that the new stuff is nothing new, rewrites are always popular but nearly always end up not much better than what was there before - after all, the previous devs didn't set out to make a mess did they.

      Its not the techniques I'm criticising really, except where they are used blindly without regard to specific problems with the codebase that they need to be used to solve. Often they're just used as cool, new, magic bullets.

    5. Re:1. Lose the attitude by PortHaven · · Score: 1

      Really, having to write 4 templates, and modify 1/2 a dozen others, in order to output a simply query/list is good code?

      Yes, that's pretty common in most of today's OOP/MVC/decoupled architecture frameworks of today. At least procedural code can be followed by it's procedural nature. Come into a framework without a roadmap. And you often are doing immense legwork to find where something is triggered from or what something is responding too.

      I wager in 20-30 years, this will be called "lasagna code" because you won't even be able to follow a single thread of spaghetti anywhere.

    6. Re:1. Lose the attitude by toddestan · · Score: 1

      Test-driven development is where you code the unit tests first, then develop the code needed to pass those unit tests. Once all the unit tests pass you have your application (in theory, at least).

    7. Re:1. Lose the attitude by gbjbaanb · · Score: 1

      yes, introduced with XP IIRC, but here's the thing - what was a good idea became corrupted by tool providers who thought "wouldn't it be a good idea to auto-generate tests for each method on a class automatically so the dev can then fill in these stubs with their test code"... and what should have been a great concept of writing tests before coding to ensure your code does what you want it it, becomes an exercise in box-checking for method test coverage, on such a small granularity scale that the tests are meaningless and have to be supplemented with even more tests that cover how those methods work together. Not to mention the massive increase in complexity when you have to code in mocking frameworks.

      Its so bad that the original TDD proponents now call what they intended BDD (behaviour driven development) to distinguish it from this myopic code-first approach. You can see this popping up here and there as the original good intent is reclaimed.

      Its kind of like Agile - where scrum is quickly taken up by management who see it as a way to "do agile" yet still have loads of process, documentation and control.

    8. Re:1. Lose the attitude by gbjbaanb · · Score: 1

      my mate's just got a new job doing WPF dev, its not working fast enough for them so he's brought in to fix it - its written by some outsourced contractors in the very latest MVVMVMMD patterm and he was describing how 'random'' it all appears - you can't trace through the code as it hops from object to object because every so often you hit a lambda function and if you're not really careful, you'll step right over that in the debugger - and then have to start your debug chain (of 100 methods calls) all over again.

      And no, I didn't make up the MVVMVMMD pattern up!

      My problem with it is that it's supposed to increase developer productivity, but no-one seems interested in keeping it simple anymore.

  8. Fix the most urgent problem first by tramp · · Score: 1

    Look at what the software is supposed to do and what it does not do at the moment. Fix this first and after that document the main functions and start replacing them one by one in an orderly fashion and document them this time. It will take time but at the end you 'll have eaten the spaghetti and your project is saved. The biggest problem in software usually is that there is no time to do it right but there is always time to do it over again.

  9. Ravioli? by Anonymous Coward · · Score: 1

    To a ravioli coder procedural code will often look like spaghetti.

  10. Don't touch it by GrahamCox · · Score: 4, Insightful

    All the advice to rewrite it is misguided. Maybe rewrite small parts that you need to to keep it working on new hardware, or whatever, but if it works, I would think that wholesale rewriting is asking for trouble. The Ars article is full of great advice about what you should do to manage a large codebase going forward, but actually it doesn't really address the question of what to do about a large legacy codebase that wasn't written with best practice. The best software is written by incremental improvement of what went before (no matter how badly written, as long as it meets its specification) - big projects written from scratch usually fail.

    1. Re:Don't touch it by ed1park · · Score: 4, Insightful

      Beware of the second system effect.
      http://en.wikipedia.org/wiki/Second-system_effect

      Rewriting code can kill you in the short term.
      http://www.joelonsoftware.com/articles/fog0000000069.html

      Or help you in the long term.
      http://notes-on-haskell.blogspot.com/2007/08/rewriting-software.html

      I recall another similar article about a rewrite of MS Office, and what a mistake it was...

    2. Re:Don't touch it by wvmarle · · Score: 1

      Not just management, you should also blame the developers that wrote it that way.

      It's a manager's job to tell how to do it; it's a developers job to implement it properly. You can't expect a manager to write perfectly modular, readable software - that's the developer's task, and blame failing to fulfill that task should be largely on the developer.

    3. Re:Don't touch it by sjames · · Score: 1

      That depends. If the developers had time to do it right and didn't, blame them. OTOH, if the code only got time allocated to it when someone's hair was on fire and they got moved on to something else as soon as the bug was papered over (to make sure they had really found the problem) rather than allocating time for the real fix, blame the management.

    4. Re:Don't touch it by ralphdaugherty · · Score: 1

      All the advice to rewrite it is misguided. Maybe rewrite small parts that you need to to keep it working on new hardware, or whatever, but if it works, I would think that wholesale rewriting is asking for trouble. The Ars article is full of great advice about what you should do to manage a large codebase going forward, but actually it doesn't really address the question of what to do about a large legacy codebase that wasn't written with best practice. The best software is written by incremental improvement of what went before (no matter how badly written, as long as it meets its specification) - big projects written from scratch usually fail.

      so very true. insightful.

    5. Re:Don't touch it by GrahamCox · · Score: 1

      You can blame whomever you like, it doesn't change the fact that you have a large, intractable codebase that you are going to have to deal with. Learn your lesson, vow to do better in future, but complaining about it after the fact is just a load of time and energy, after which expenditure your code will be.... exactly the same.

    6. Re:Don't touch it by rtfa-troll · · Score: 1

      Beware of the second system effect. http://en.wikipedia.org/wiki/Second-system_effect

      Rewriting code can kill you in the short term. http://www.joelonsoftware.com/articles/fog0000000069.html

      Or help you in the long term. http://notes-on-haskell.blogspot.com/2007/08/rewriting-software.html

      I recall another similar article about a rewrite of MS Office, and what a mistake it was...

      What the second essay is missing is that, if you followed Joel's advice which is - refactor - modularise - improve then by the time you get to the long term, your software will be almost as much re-written as in the first case but will do more. In fact it may have become two pieces of software; one which does the aim of your rewrite and another one which provides the compatibility features for peple who need the old feature set.

      --
      =~ s,(.*),<sarcasm>$1</sarcasm>,g if any_point_you_wish();
  11. Re:Don't put up with it. by rmstar · · Score: 3

    I'd rather be homeless than be in charge of a project my boss doesn't really care about. Talk about the fast track to nowhere. Even if by some maricle you do pull it together, nobody will know or care.

    If things go well, your bank account will know, for example.

    What does it even mean "my boss doesn't really care about" a project? Is his vision somewhere else, but has given you the job of guarding the crucial machinery on which everything else builds?

    (And being homeless sucks badly, by most accounts.)

  12. Working Effectivley with Legacy Code by Anonymous Coward · · Score: 1

    Personally I found the book 'Working Effectively with Legacy Code' (http://www.amazon.co.uk/Working-Effectively-Legacy-Robert-Martin/dp/0131177052) offers some great suggestions about how to integrate new functionality and changes into legacy systems.

  13. 200K Lines not that much by PerlPunk · · Score: 4, Interesting

    I have spent most of my career as a software developer inheriting and updating such spaghetti code bases. Here are few remarks and some of my experiences around this:

    1. 1) 200K lines is not such a formidable size. If your average module size is 1000 lines of code, that's 200 separate modules. Or if the module size averages 2000 locs, that's 100 modules. Gradually getting your head around the modules is not as big a problem as it seems, even if there are many interdependencies between modules. However, if the average module size is something on the order of 10K or 20K, then you really are dealing with spaghetti code, and that's quite a bit harder to figure out than if the module size on average were around 2 or 3K.
    2. 2) For the time being, treat the whole application like a black box, which means not worrying too much about how well it works until you have to fix some "bug". At that point, figure out how it works only insofar as you need to in order to get your bug fix in, and record your lessons learned in a wiki and in comments in the code. Refactor as you go along, if feasible.
    3. 3)Being able to step through code is really helpful when trying to understand a poorly documented code base--even if the code is well structured. A number of technology platforms (like Java JVM) offer remote debugging.
    4. 4) You can reverse engineer these things and produce a set of business specs with which to port the application to a new platform. Right now, I'm on a project that is porting 125K lines of COBOL code that ran on OS2 to an Apache/mod_perl technology stack. Our team consists of 2 cobol developers, who are producing the specs from the code, and 3 perl developers who are porting it. The key here is to capture the business requirements and the user interface behavior. Once you do that, how you implement it on the new platform is quite straightforward. HOWEVER, this approach is not advised unless your company or gov enterprise has lots of time, deep pockets, and a commitment to seeing the project through to its eventual success.

    In summary, don't be too scared of a legacy spaghetti code base. These things can be understood well enough in time to refactor or port to a new platform.

    1. Re:200K Lines not that much by mrjb · · Score: 1

      1) 200K lines is not such a formidable size. If your average module size is 1000 lines of code, that's 200 separate modules.

      What are these "modules" that you are speaking of? And "separate" - could you elaborate? I've seen code where one couldn't help to ask the above questions. Asking the architect about what modules the system had yielded the answer "It's complicated, you'll just have to get used to the system". Which meant, committing the full 200k lines to your brain and needing to understand the code as a whole, rather than as pieces and modules. In the end I found out there's a design pattern they followed. The official technical name of that design pattern is "big ball of mud".

      --
      Visit http://ringbreak.dnd.utwente.nl/~mrjb/growingbettersoftware to download your free copy of the book
    2. Re:200K Lines not that much by wvmarle · · Score: 2

      1) 200K lines is not such a formidable size. If your average module size is 1000 lines of code, that's 200 separate modules. Or if the module size averages 2000 locs, that's 100 modules.

      You make a very big assumption here, and that is that this code is written in neatly separated modules. The submitter asking for help; calling it "spaghetti code" that has been "cobbled together" over a long period and presumably by many different developers; those points make me doubt you can make such an assumption.

      It can very well be a single "module".

    3. Re:200K Lines not that much by loufoque · · Score: 1

      I'd have to agree on this.

      As a software developer I've experienced this most of the time, working with code bases much larger than this without any sort of documentation. It's not unusual for single files to be more than 4,000 lines of code and to have thousands of files, with the occasional crazy branching 10 levels deep within a single function.

      It's just something you have to deal with as a professional software developer. It's not really a problem. Knowing how to use your tools efficiently comes a long way. I personally use grep and find a lot.

  14. Re:be selective by udachny · · Score: 1

    Open documentation? Pfffft. That's a lame advice. No no, what you want to do is mix it up some more, obfuscate the code, change variables to make them global and reuse them everywhere but all for different purposes. Merge large files together and brake small files into even smaller ones.

    Remove any useful comments from the code, but add plenty of comments like this:

    // adds 1 to i, waits until i is greater than 10 then adds 2 to a.

    Now that's a comment!

    Then leave the project and see the other guy come in and pull his hair out. Life is hard, make it funny.

  15. Why? by Anonymous Coward · · Score: 1

    The really frightening tought is that there are many 40 year old first year CS students.

    Why?

    It's not like they're wearing a Speedo in class or anything.

  16. Standard procedure by WinstonWolfIT · · Score: 1

    Per John Lakos, almost any bad interface can be wrapped in a good one. Slice off an appropriate slice of dodgy code, wrap it in a testable interface, write the test code to baseline its behaviour, and then when it makes business sense, you can refactor that slice of code. If it doesn't make business sense, you don't touch it.

    1. Re:Standard procedure by russotto · · Score: 2

      Per John Lakos, almost any bad interface can be wrapped in a good one. Slice off an appropriate slice of dodgy code, wrap it in a testable interface, write the test code to baseline its behaviour, and then when it makes business sense, you can refactor that slice of code. If it doesn't make business sense, you don't touch it.

      You've never seen real spaghetti code if you believe this. In a really nasty ball of spaghetti, there's nowhere to make the cut; any significant section of the codebase essentially depends on the entire codebase. Among other sins: code at low level will make decisions essentially based on which high-level caller ultimately called it.

    2. Re:Standard procedure by WinstonWolfIT · · Score: 1

      As I've done significant refactoring on a system architected against a pool global variables, actually, yes I have. My comment stands. If my track record > yours, well there you go.

    3. Re:Standard procedure by Hognoxious · · Score: 1

      Among other sins: code at low level will make decisions essentially based on which high-level caller ultimately called it.

      Plus all variables are global & some are used for different purposes in different places. Am I right?

      --
      Confucius say, "Find worm in apple - bad. Find half a worm - worse."
    4. Re:Standard procedure by russotto · · Score: 1

      Plus all variables are global & some are used for different purposes in different places. Am I right?

      You bet. In fact, there are multiple "scratch" globals and it's up to you to figure out what code paths use which ones. Most likely, there already are some code paths which overwrite these incorrectly, which accounts for some of the bugs the existing system exhibits.

  17. NOT like a chemical plant by Troyusrex · · Score: 2

    The difference between software development and most manufacturing is that they produce the same or very similar product thousands or millions of times where we produce a different product every time. This "building an app is like mass producing a chemical" philosophy is one reason why most software shops have insane amounts of unneeded documentation and overhead. I certainly agree that some standards, processes and documentation is needed but it should be kept to the bare essentials as every bit of work done that doesn't directly build a product could well just be a waste of time.

    1. Re:NOT like a chemical plant by Anonymous Coward · · Score: 1

      I think you misunderstand. The software is not being likened to the chemical (i.e. the output of the chemical plant), it is being likened to the plant itself. The data output by the software would be the equivalent of the mass produced chemical. The software engineer would be the plant designer, not the shop floor worker.

    2. Re:NOT like a chemical plant by drew_eckhardt · · Score: 1

      >This "building an app is like mass producing a chemical" philosophy is one reason why most software shops have insane amounts of unneeded documentation and overhead

      In 20 years working as a software engineer I've yet to encounter a software shop with insane amounts of unneeded documentation. The majority of software organizations I've dealt with had inadequate documentation and process which led to lower quality for customers, lower developer throughput, and unpredictable release schedules.

      Usually this comes from deep seated religious beliefs among executive teams and mid-level managers. To quote one CEO "Test code doesn't ship to customers." He practiced what he preached, directing employees to build product and not test too much. Another company managed a two billion dollar market cap from a product very similar to one the he abandoned because the schedule kept slipping and it never worked well enough (although engineering staff kept strongly suggesting hardware validation).

      Nothing can change that religion. You can apply better process to your own projects and illustrate order-of-magnitude lower defect rates and time to fix bugs that result from that compared to similar sized projects in the organization without the process. You can talk about the business benefits from positive experiences in other companies. You can sometimes get them to read books like _The Clean Coder: A Code of Conduct for Professional Programmers_. You can share your amusing anecdote about the company you didn't work for because one of the founders did not believe in unit tests so you knew they were going to crater due to low quality and long unpredictable release cycles which had their VCs rescind funding due to customer issues with quality and long and unpredictable delays for bug fixes. You can get other executive team members on the right side and attempt an intervention although the same skills of persuasion which get tens of millions from investors work to move them back. You can go to the board of directors although they're friends with the executive team and it doesn't end well.

      Occasionally it's just ignorance. Software engineers can go through a lot of positions without stumbling across someplace that does a good job. This is easily fixed - once competent people have seen how much tedium process removes from their lives and how it lets them focus on interesting problems they get with the program.

      While software development is an art, there are accepted processes not too different from mass production that make higher quality, shorter delivery times, and more predictable schedules likely. Although that doesn't sound like fun they do allow the engineer to spend more time on art (which is fun) and less on mechanics so it's a win-win-win for customers., company, and coder.

      I have encountered unneeded overhead which can be another facet of the same problem or something else. Sometimes companies grow too fast and create extra positions filled by people that need to justify their jobs. Sometimes the executives who direct less testing become unhappy with the unpredictable product cycles which result and decide to apply the daily meeting (except for 1-2 hours) from the agile world without the things which make agile work.

  18. Inexact Results by SuperKendall · · Score: 5, Insightful

    Rewrite it from scratch using the spaghetti code version to run correctness tests to verify you haven't changed the behaviour.

    And just how are you supposed to write "tests for correctness" when the very concept of what is "correct" is embedded in the code?

    Any such tests would embody your own notions of what is correct based on your understanding of a codebase that cannot be understood.

    Furthermore, Doom is quite a different thing. You have an end result that can be somewhat different and it doesn't matter - it could render textures such that they appear rather different but if you find it visually OK then it's fine.

    No such luck with business software which usually has extremely rigid and exactly output, often output other systems are depending on being just so. There is no room for alteration of behavior, yet as I said no-where exclaims all of the features of the output you cannot possibly understand....

    I agree with a few responses that the only way to proceed is to re-write tiny parts, that at most affect one other system in the company - with the explicit buy-in from those other groups something may change, and the understanding you may have to back out your changes wholesale if you cause too much disruption.

    Can't get buy in to proceed? Then quit or work with the code as is.

    --
    "There is more worth loving than we have strength to love." - Brian Jay Stanley
    1. Re:Inexact Results by maxwell+demon · · Score: 1

      And just how are you supposed to write "tests for correctness" when the very concept of what is "correct" is embedded in the code?

      Simple: If the original code is the specification, then the tests have to be written such that they pass with the original code. That is, the original code is the test suite for the test suite.

      --
      The Tao of math: The numbers you can count are not the real numbers.
    2. Re:Inexact Results by Lonewolf666 · · Score: 1

      If your new code does what the old code did when both are fed the same input, you're good to go. Exactly how you go about setting up these tests can be a nightmare worse than dealing with the original spaghetti code, but at least that is the idea.

      The sphagetti-ness of the old code often means you don't have clearly defined units and no easily understood intermediate results. So the answer is simple:
            You are limited to system-level tests. That is, you feed the old code input at the user interface and look at the end result. Of course, that does not help much to understand the original spaghetti code. Your system tests merely tell you if you have sucessfully duplicated the behavior of the old system. They won't give you many clues about how to get there :-(

      --
      C - the footgun of programming languages
    3. Re:Inexact Results by SuperKendall · · Score: 1

      Simple: If the original code is the specification

      HA HA HA HA HA HA.

      You've never written code for a corporation before, I can tell.

      The code IS the specification. All other documents are LIES.

      --
      "There is more worth loving than we have strength to love." - Brian Jay Stanley
  19. Re:A meal fit for a programmer. by galaad2 · · Score: 1

    don't forget a fork.
    all spaghetti needs a fork, even spaghetti code. /:)

    --
    root@127.0.0.1
  20. Re:Sequence Diagrams by mrjb · · Score: 1

    Even do it at home if you wish to

    Don't fall for it, it's a trap. Before long, it will be expected from you. At home, I don't get paid for the hours I put in. At home, I don't receive any recognition for the work I've put in. Using home-made stuff at work puts the ownership of your stuff in question. I choose to keep home and work separated. At home is where I work on MY stuff.

    --
    Visit http://ringbreak.dnd.utwente.nl/~mrjb/growingbettersoftware to download your free copy of the book
  21. Re:in my experience... by Anonymous Coward · · Score: 2, Informative

    Usually when the inxperienced programmer does the rewrite, "initial results are promising".
    That is, it is possible to quickly build a basic framework with badly designed error handling and
    only part of the requested features.

    When it is tested in real life, lots of omissions and problems are found.
    Once these are fixed, the result is as messy and unstructured as the initial system was before
    it was rewritten.

  22. At the very least by NotSoHeavyD3 · · Score: 1

    Instead of multiplying how long you think something will take you by 2 when you give your estimate(since everybody underestimates how long it takes to do something) multiply it by 4. (Since if the code is that bad you'll need the extra time to A:Find it and B:Find out the first way you fixed a problem broke something else because the code is garbage.) Can you tell I'm working on spaghetti code now?

    --
    Did you know 80 to 90% of the moderators on slashdot wouldn't recognize a troll even if one dragged them under a bridge.
  23. Big Ball of Mud by QuietLagoon · · Score: 1
    A commentary on spaghetti code and why it gets that way.

    .
    A BIG BALL OF MUD is haphazardly structured, sprawling, sloppy, duct-tape and bailing wire, spaghetti code jungle. We’ve all seen them. These systems show unmistakable signs of unregulated growth, and repeated, expedient repair. Information is shared promiscuously among distant elements of the system, often to the point where nearly all the important information becomes global or duplicated. The overall structure of the system may never have been well defined. If it was, it may have eroded beyond recognition. Programmers with a shred of architectural sensibility shun these quagmires. Only those who are unconcerned about architecture, and, perhaps, are comfortable with the inertia of the day-to-day chore of patching the holes in these failing dikes, are content to work on such systems.

    Still, this approach endures and thrives. Why is this architecture so popular? Is it as bad as it seems, or might it serve as a way-station on the road to more enduring, elegant artifacts? What forces drive good programmers to build ugly systems? Can we avoid this? Should we? How can we make such systems better?

    We present the following seven patterns:.....

    1. Re:Big Ball of Mud by gl4ss · · Score: 1

      that article is a big ball of mud.

      but it makes a good point, you need to first focus on that the wanted features work.

      --
      world was created 5 seconds before this post as it is.
    2. Re:Big Ball of Mud by Evil+Pete · · Score: 1

      The Big Ball of Mud has a lot of wisdom in it. Came across it years ago. It is still relevant. The point of the Big Ball of Mud antipattern, as described, is that they WORK. That is why they are popular. They may not work very well when they scale up but they are still functional enough. The trouble with the example here is that the domain knowledge must be preserved. Rewriting the code will likely lose domain knowledge, this is not acceptable. There is no easy answer. It will require analysis, comments, documentation, writing unit tests, careful rewrites of components and testing. Make it simpler and usable, teach how principles about how to add better code and offer support. The goal should be to make it easier for the user and/or the next dev to use or maintain it.

      --
      Bitter and proud of it.
  24. Re:in my experience... by foniksonik · · Score: 1

    This. All too frequently.

    --
    A fool throws a stone into a well and a thousand sages can not remove it.
  25. Good luck with that by Anonymous Coward · · Score: 2, Insightful

    Your employer probably isn't interested in spending the time and money on a re-write. Nor are the clients going to be interested in waiting that long for new features, either.

    You will be made to figure it out and add features, or you will be shown the door.

    1. Re:Good luck with that by Grishnakh · · Score: 1

      As the other responder said, this doesn't appear to be the case for this particular project in TFA. However, you're right, what you describe is normal for most projects. The way to handle it is this: since management isn't interested in doing a re-write, you just do your best trying to figure it out, which of course is not going to be very successful. Keep making excuses about how bad the code is when deadlines fly by. All this time, be sure to be looking for a new job on Dice.com. As long as you're making some kind of progress, management will keep you around, because very slow progress is better than no progress at all (which is what you get if you fire the developers). Sooner or later, a new opportunity will present itself to you and you can ditch that dump.

      Of course, then you start the cycle all over again. This is the life of a software engineer.

    2. Re:Good luck with that by datavirtue · · Score: 1

      Just back from dice.com. Can't believe the enormous laundry list of requirements and experience with no mention of moving the "right candidate" into the position for almost every job listing. It's almost like satirical comedy.

      --
      I object to power without constructive purpose. --Spock
    3. Re:Good luck with that by Grishnakh · · Score: 1

      Yep. Kids, I recommend finding another major while you still can. I hear medicine is still a pretty good field, and pays much better than this.

  26. Re:Obvious by maxwell+demon · · Score: 1

    While this may be the best solution, it will probably be very hard to sell it.

    --
    The Tao of math: The numbers you can count are not the real numbers.
  27. Re:Why? by maxwell+demon · · Score: 1

    FTFA: "They've recently learned some hard lessons about the consequences of non-existant configuration management. Their maintenance efforts are also greatly hampered by the vast accumulation of undocumented "sludge" in the code itself."

    --
    The Tao of math: The numbers you can count are not the real numbers.
  28. Re:be selective by maxwell+demon · · Score: 1

    // adds 1 to i, waits until i is greater than 10 then adds 2 to a.

    Now that's a comment!

    Didn't they teach you that comments which re-state exactly what the code does is bad? Here's how that comment should look like:

    // increments i until large enough, then adjusts a

    Everyone who wants to know the details can refer to the code. The comment shall not give the what (10) but the why (large enough).

    SCNR :-)

    --
    The Tao of math: The numbers you can count are not the real numbers.
  29. done in one hour. by Anonymous Coward · · Score: 1

    just put it all inside a class
    now you have nice object-oriented code

  30. 200k lines isn't too much by SpaghettiPattern · · Score: 2

    In the past years I have been several times in such a predicament. Huge amount of code and the function of the system is not completely clear. The original developers are gone, the system isn't well documented and only a handful of people know how how it should behave. As a matter of fact, tomorrow I will start coding on one system we can no longer support as hardware, OS and used libraries and frameworks are outdated and/or discontinued.

    Reengineering and rewriting is usually the best option. However, you need skills and experience in order not to make the same mistake the previous developer did. Of course, management must trust and approve your actions.

    A few dos:
    * Learn at least UML use cases, components diagrams and sequence diagrams.
    * Make use cases and check these with affected parties.
    * Start of with a rough component model of the new system.
    * Make a clear picture which nodes (hardware + OS), subsystems (units performing a function), software components (modules containing data, modules performing a function, etc...) and agents (users, triggers/schedulers) are involved.
    * Draw the interactions between the subsystems and/or software components.
    * Clearly document which interactions are on-line and which ones are batch/background/off-line.
    * Specify interfaces. (Used file formats, protocols, software library interfaces if you will.)
    * Slowly refine your model until you feel comfortable with it.
    * Make a rough class model and keep usability and maintainability in mind. Backtrack if necessary.
    * Divide software components between "dumb" containers of information (e.g. plain Java beans) and components performing functions (business logic if you wish.)
    * Decide which interfaces to make public and which not.
    * Describe restricted/private bits of code just enough for maintainers to understand them. And nothing more than that.
    * Make as much unit as necessary for your components. Unit test enough functionality.
    * Communicate your results regularly and refine your model where applicable.
    * Define integration tests and do these very seriously.
    * Define regression tests and perform these very seriously.
    * Make involved parties accept parts of the system according to performed integration and regression tests.
    * Try to plan gradual decommissioning of the legacy system.
    * Document the system "enough". System architecture (from UML), references from architecture to code, installation manual and operational manual are the most important ones.
    * Try to achieve longevity in the documentation. Abstract details and convince involved people that that is a good thing.
    * Define 1st, 2nd and 3rd level support. Preferably you should remain 3rd level support to better enjoy sleep.
    * Conform to standards and practices if they reduce discussion and enhance clarity.
    * Use well established techniques. E.g. JPA and JAXB.
    * Allow well established component manufacturers to make your programming life easier. E.g. Apache Commons.
    * Be tidy.

    A few don'ts:
    * Avoid OO pattern overkill.
    * Don't take the quick and dirty option too quickly. Those decisions will haunt you eventually.
    * Avoid making everything public. Documenting and maintaining public interfaces is more expensive.
    * Try to avoid big bangs.
    * Avoid less well established component manufacturers. My next project did use components from less established component manufacturers and their sell by date has generously expired.
    * Don't allow babling "architects" to make a mess of your system. But don't alienate them either.

    I may have forgotten a few things but this is all stuff I consider even for smaller projects.

    --

    I hadn't the slightest objection to his spending his time planning massacres for the bourgeoisie... (P.G. Wodehouse)
  31. Re:Don't put up with it. by __aaltlg1547 · · Score: 4, Insightful

    If that's the case, the stated or implied directive is don't break this. Which means probably no major rewrite.

  32. Re:in my experience... by TheRaven64 · · Score: 1

    It's a very old saying that the first 90% of the project takes the first 90% of the time, and the remaining 10% takes the other 90%. When dealing with old codebases, however, 90% is often good enough. I've seen programs that were written with one set of requirements and then those changed. They ended up with massive abstraction layers to support multiple back ends. Then 5-10 years later they were using the abstraction layer to abstract a single implementation. And the abstraction layer wasn't a good fit for the front or the back. A rewrite can just omit the abstraction layer entirely, significantly reducing complexity. Sometimes this makes the code harder to refactor in the future, but often it's easier to then insert a new abstraction layer than to try to adapt an existing one.

    --
    I am TheRaven on Soylent News
  33. Re:200K Lines not that much (I disagree) by loufoque · · Score: 1

    I am assuming that the porting developers are using source code management tools, following a standard, and are adhering to a common design philosophy (coding for exceptions, using a consistent naming standard, comments that address the what of the code (not the how), and indenting code for readability)

    In large code bases, it can be rare that everything follows the same naming conventions, indenting style, or even programming style, simply because hundreds of people work on the code, and different teams with different skills edit different parts of it.
    The only unit where this tends to be true is the file.

  34. To All Tutoria And Book Authors by assertation · · Score: 1

    I've dealt with a number of legacy code bases, done poorly. Some of the worst examples were done by veteran procedural programmers who picked up an OO language via tutorials.

    The worst of their evils could be greatly reduced by all tutorial and book authors, by stating, promiently, the rule of thumb that if the module they are typing goes past one screen in height that they should start thinking about breaking it into another module.

    Almost every language has a module of some kind ( procedure, function, subroutine, etc ).

  35. Re:Abject terror! Rewrite or leave alone. by Gorobei · · Score: 1

    While I usually don't advocate "use language X," a mess of this size (200K LOC) with a non-CS developer team, may be a pretty nice fit for a Python based retrofit.

    1. Get source code control in place
    2. Get automated builds/testing in place
    3. Define functionality by writing Python unittests

    The problems you encounter in step 3 will drive how you incrementally, or otherwise, refactor the code:
    a) can Python even interface to the system in a reasonable way?
    b) can people even agree on a good test suite?
    c) does running a test require massive setup of files, external processes, specific machines being up, etc?
    d) can two people run the test suite simultaneously?
    e) does it work on weekends?

  36. Re:Better solution by Anne+Thwacks · · Score: 1

    Its spaghetti we are talking about here. Bolognaise source is the appropriate treatment - although you might want to add some chilli to your standard recipe, as it is code.

    --
    Sent from my ASR33 using ASCII
  37. Re:Don't put up with it. by ralphdaugherty · · Score: 2

    If that's the case, the stated or implied directive is don't break this. Which means probably no major rewrite.

    This should be +5 Insightful. It's the bottom line for production software.

  38. Read The Article by Antique+Geekmeister · · Score: 1

    The article is excellent. It's publishing guidelines very similar to those I use, and my colleagues use, when dealing with our business partner's accumulated software projects, and covers it very well: I intend to use it as a checklist for spaghetti code integration projects.

    I'd emphasize the switch to good source control management (SCM). too many workgroups have undocumented workflows, and benefit profoundly from switching to or learning to properly use a robust system. This process also helps identify who is the primary spaghetti code author. In such a project, there is often a particular developer or "architect" who has been carrying around the functional map of this project in their head. Their time and commitment to get that map into documentation so others can work with it is absolutely necessary to such projects, SCM is often the first step towards this. And if that core developer or architect doesn't agree with the project, _fire them as fast as possible_, because they will hamstring every effort to move to any cleaned up architecture.

    Also note that most such core developers or architects have actually been wanting to do something like this cleanup for _years_, and simply haven't been allocated the time and resources to do it. There are risks: repairs are often much cheaper and safer than the kind of large scale this kind of cleanup represents, and the actual benefits have to be presented to the managers or clients to get them to invest manpower, so that core developer often has a huge emotional frustration with the original code. Working with them to get their buy-in, and being willing to trade minor points of disagreement with them to get their cooperation with big issues are priceless on such large projects. Otherwise, they can and often do backstab every integration effort as "wasted time" or "not sufficient", even claiming both at the same time.

  39. Reminds me... by Cute+Fuzzy+Bunny · · Score: 1

    Reminds me of how as a young lad, I went to work for a jewelry company's "IT Department". I put it in quotes because the department consisted of me, a supervisor who couldn't code, and a department head that had no idea whatsoever as to anything that happened on the company computers. Someones nephew or son that got put on the payroll is my guess.

    Anyhow, they had about three billion lines of applications written in Dibol, all spaghetti code, no documentation, last time they had employed anyone who could code was about 2 years prior, so everyone just worked around the bugs in the applications.

    I worked there for about 7 months, scrubbing the code and then going home and writing the documentation on the code. Documenting was never anything they had asked for or specified in my goals/objectives. After 7 months when I'd fully documented everything on my own time and the system was working fairly well, they decided that things were going pretty well and they wanted another family member on the payroll, so they let me go. Six months later, the wheels came off of something because one of the monkeys pushed the wrong buttons. I offered to sell them the documentation I'd written and refer them to some other programmers who would then be able to fairly quickly and cheaply fix what they broke. Or they could hire someone full time and maybe in 6-9 months they might fix it.

    Didn't have to buy my girlfriend any jewelry that year. Swapping boxes of 3 ring binders for a bag of random jewelry in a parking lot at night is still one of my fondest memories.

    See kids, do your documentation and eat your vegetables...they're good for you!

  40. Tests, tests and more tests by richieb · · Score: 1
    Before you attempt to change this kind of code base, you need to understand what it does. The best way is to write unit tests that exercise system. Think of tests as very precise requirements. Once a decent test suite is in place (200 to 300 test cases) then you can start thinking about fixing, rewriting portions of the system.

    Rewriting from scratch is probably the worst thing you can do. See this article by Joel Spolsky,,

    --
    ...richie - It is a good day to code.
  41. Don't rewrite; evolve by QilessQi · · Score: 1

    I've been called in to work on a number of software projects over the years, some of which I was dismayed to find were bloated monstrosities. I refuse to leave a mess behind, even if it's not my mess... and if I don't know how long I'll have to work on that code, the sooner I start cleaning the better. Here's my strategy, more or less:

    1. 1. Come up with a package or module structure which is reasonable, and not too far off what currently exists. Keep it around as a target, something to work towards, but don't start reorganizing things just yet.
    2. 2. Find the lowest-level code and consolidate it into sensible utility classes -- string utils, date/time utils, etc -- conforming to the planned module structure. Get rid of duplication throughout the codebase. Write unit tests first so you can be certain that the migrated code behaves like the original.
    3. 3. Whenever you have to work in one specific area of the code base, focus on refactoring that and that alone. Start by documenting what it does and how it works: otherwise you WILL screw it up. If you find something that doesn't make sense, flag it with a TODO comment but don't screw around with it until you understand what it's doing. Write unit tests beforehand to avoid breakage. Repeat.
    4. 4. When time allows, delve into neighboring areas of code once you become familiar with them. Prioritize by considering frequency of use and degree of messiness: think "bang for the buck".

    But for pity's sake, don't just leave the mess as a mess.

  42. Re:Write a program that rewrites the code by jc79 · · Score: 1

    No-one does that any more. We just boot up a simulated world full of imaged human minds and overclock the substrate until they've rewritten the code for us. After that we wipe the simulation before they can develop an exploit that lets them jump out of the VM. Much simpler than hand-coding AIs.

  43. Being anally retentive is not a winning stragegy by WaffleMonster · · Score: 1

    I stopped reading shortly after "I am aggressive when it comes to coding conventions"

    The mention of Agile as a positive strategy and the volumes dedicated to "format" of code are only useful to scratch an itch. They are only valuable in the mind of the author and those who think like him and rarely have any effect on outcomes.

    Ridigity * is not a strategy in and of itself. It is the preference of someone who is anally retentive and change adverse.

    The wins from his scheme are like the wins from modern language features. They can only go soo far to reinforce or mitigate actual outcomes in a project lifecycle.

    What makes or breaks large scale projects is not a vigorous environment but a creative one.

    One that encourages creative solutions to effectivly understand and manage global complexity. Everything else is as TFA says "noise".

    I would much rather pay someone to write code that "looks" like shit if means they are spending more time on the big picture than pay someone who is obsessive compulsive with no time or capacity left to reason about WTF is over the horizon.

    There is no substitute for thought. If procedure and process were that important machines would be writing all of our software for us by now.

  44. I am in a similar situation right now. by drolli · · Score: 1

    Its not 200k Lines, more on the order of 10-20kLines (depending onf the count; its written in a highly compact language). It is not my main task to restructure it, as a matter of fact i have rediculously little time budget for it, give the current state of the code. My task is to integrate new features into the code. However when i looked at it an rewrite seemed inevitable.

    Let me break dow how i try it:

    a) Analyze why the problem is there. There are two aspects of it: Is there a fundamental problem with the qulification of the team members (in my case, there is - they are not programmers, but experts on other topics). The other question: Is there something inherently wrong with the processes (there was. Two parts of the teams uses the Version control system based on the assumption that its only purpose is to snapshot their "working" state - which contributed hugley to commits mingling all kinds of feature updates).

    b) If you look at the feature which you should implement, what is the ration of the work it *should* take (in my case: not more than 2h) to the ratio it *would* take in the current structure (in my case: 20h). Analyze what is the worst point for this feature (in my case: not separating certain layers of reading/converting/validating input and not having any explicit delcaration of a certain data structure).

    c) what can you do? In my case: rewrite just this part in a better way (not perfect), with the following criteria: use the same or less time for the feature you should implement, includign the conversion. Demonstrate the power of the approach to you co-workers by integrating them in the process. In my case i used roughly 12h for rewriting the procedure, 6h to test it against ther old code, 2 h for sitting down with my boss/project manager and explainign it. After this he could include the changes he wanted himself easily in a negliglible time. (yep, i made myself obsolete for this task, and that was highly appreciated because i am not very cheap to hire)

    d) discuss a clear strategy how to upgrae the code, piece by piece to a decent level, and make some showcase where infrastructure improvement would help, in parallel to what you did up to know. That is very important, since the willingness to support the conversion a new structure depends on progressively showing advantages and clearly demontrating progress. Real artists ship (i work as a consultant). If we miss a deadline in this project that would be *bad*.

    e) explain what you are doing in a manager-compliant way. A lesson in communication traning you get as a consultant is *never ever* speak negativly about any product or service in general. It could be well that the head of department would ask me why i see certain steps necessary. My answer would be quite general, like: separate expert knowledge from implementation. Or: make it easier to maintain and *save* work in the long term. Be careful in that context with comments about the code quality. There is no *bad* working code. While you wish to say: this code in incredibly incoherent, taped together work of twenty different trainees supervised by sombody who did not know about the system himself, say the following: I think we can imporve the code by intrioducing a database backend. I believe that a more unified way of describing the inputs to the code will save the time of [increbly good technical expert who no spend 25% his time huntig obscure bugs]. If you go down the other road and mock the code, the following things can happen: a) the project gets cancelled, because management believes its beyond repair b) the mangemer does not hire you because he was the one who started the project 10 years ago in an obcure form which you know about c) you will loose the support of co-workers for mocking them and face a harsh review should you rewrite no be the flying pig which you promised.

    ok thats my 2 cents.

  45. 200k lines? Did he only count headers? by kfsone · · Score: 1

    200,000 measly lines of code?

    Having done a lot of code maintenance - including Y2K certification of the "MMDF" code base (first comments/headers would have negative unix timestamps) - he needs to start by learning about code beautifiers and finding a style he finds easy to read.

    Then, personally, I try to storyline the code. Some times, more creatively than others but those are extreme cases.

    --
    -- A change is as good as a reboot.
  46. First... by ChrisLeif · · Score: 1

    Prepare three envelopes.

  47. The Timeframe by SuperKendall · · Score: 1

    If your new code does what the old code did when both are fed the same input, you're good to go.

    I am curious just how long the project you propose will take to complete given that you need to produce an infinite combination of inputs to succeed.

    Your basic idea is not bad, but it's simply impossible to apply to the whole system at once. That's why I suggested a small piece that interfaces with at most one other system, so you can in practice limit inputs and have somone else really tell you what is flawed in your output, because you will have no idea. You will still forget many bits of key input that lead to dramatic errors, but hopefully after a year or two most of that will be ironed out without too many people fired.

    Your concept also requires the system to be able to be run wholly in isolation to run input through, something nearly impossible to do for many IT systems, ESPECIALLY the spaghetti kind. If tey couldn't write good code why do you think they would have made it easy to test?

    With an ancient and bad code base there are NO aspects that are in your favor or will help in any way.

    --
    "There is more worth loving than we have strength to love." - Brian Jay Stanley
  48. Freeze the spaghetti by davidwr · · Score: 1

    ... code and save it for the next management luncheon. Serve it up with marinara sauce. If the managers get sick, then toss it. If they don't, then give them the leftovers.

    --

    How much of this post is literal and how much is metaphor is left as an exercise to the reader...

    ... or future job applicants.

    --
    Knowledge is how to play a game, intelligence is how to win, wisdom is knowing what game to play.
  49. Wrong, incorrectness readily found by SuperKendall · · Score: 1

    If nobody knows if the original program is functioning correctly then nobody knows if the replacement is functioning incorrectly.

    Another person who has never developed software in a company I see.

    You'll find ZERO people that are willing to confirm your output is correct.

    However you'll find hundreds eager and willing to find flaws in your output. Sometimes even if they have to make it up, or sometimes even if they just aren't sure. For any question raised you must be prepared to prove that any questioned output is correct. Any misstep means the re-write is canceled.

    Often (and I am not kidding here) it is easier to simply start a new company and use better software from the outset.

    --
    "There is more worth loving than we have strength to love." - Brian Jay Stanley
  50. Re:Why? by Grishnakh · · Score: 1

    There's a lot of 40-year-old women these days who look pretty hot in a speedo. People aren't aging as badly as they used to.

  51. WORK WITH THE VENDOR by darue · · Score: 1

    none of these general principles people are putting forward for this case are that critical, G2 is weird, don't start out assuming everything's broken and needs fixed. Some bad experience happened, but they apparently fixed it and are still productive with the system, be cautious and learn the system. Best advice I can give on this is WORK WITH THE VENDOR of G2, they can probably help the guy get up to speed. The point is, they've got a working good system that has been evolving for 20 years or so, dont think you're going to just rewrite the damn thing. There may be real good reasons he couldn't possibly know yet. Spend a year studying the system, then worry about about improvements. If the want you to run some classes on best practices while he's learning, that's cool. I also don't think he's "inherited" anything, the employers are not going to let the guy launch off on a crusade to fix what is working well for them already. Humility is appropriate here.

  52. Re:stackexchange. by rwa2 · · Score: 1

    Yeah, it was posted on ArsTechnica yesterday too (kinda like a professional, adult version of Slashdot).

    But it's OK, I still stick to Slashdot because I enjoy reading the trolls for some strange reason.

  53. Make a plan to slowly evolve the software. by anwyn · · Score: 1
    Good software is not designed by the central committee; The central committee screws up everything.

    Good software evolves.

    You need to forget all grandiose plans to fix the software, especially if the ideas come from academia. Become unprincipled with respect to practicality.

    The software has already evolved a lot. If you attempt to recreate from scratch, you will almost certainly repeat previous errors, even if you avoid the current maintenance mess.

    The problem is that the software has evolved towards external goodness, while ignoring maintainability goodness.

    Make a secret plan to slowly evolve the software towards maintainability.

    Slowly sneak maintainability and sound software practice in the back door when no one is looking.

    Scream loudly about how big the mess is and how amazing it is that anyone can make any changes at all to it.

    Make the point that it is not how well the elephant dances, but the fact that the elephant can be made to dance at all. This will give you more time.

  54. Spaghettii.... mmmm by andrew2325 · · Score: 1

    'Tis still my favorite dish. When someone comes in behind you and "cleans up" your code, you often lose a bit of functionality... If not entirely. I agree things need to be cleaned up from time to time, but I've run into some problems like that. And nah, I don't think I'm Linus Torvalds or anything. I've done some tinkering throughout the years though.

  55. I'm in a slightly similar position myself... by Simon+Brooke · · Score: 1

    I feel his pain. I'm currently dealing with over 5,000 badly written, undocumented Java classes. Just because it's object oriented doesn't mean it isn't spaghetti.

    --
    I'm old enough to remember when discussions on Slashdot were well informed.
    1. Re:I'm in a slightly similar position myself... by PortHaven · · Score: 1

      Yes it does....

      OOP becomes "Lasagna Code", as least procedural code allows you to follow the spaghettic noodle of code logic. OOP lasagna code essentially leaves you wondering what piece of cheese is triggering your sausage.

      Granted, you get to easily determine if you're dealing with sausage, sauce, cheese or even a extended sub class of Rigotta cheese. But unmapped OOP I fear will be far worse than the spaghetti code of yesteryear.

      Be afraid, "lasagna code" cometh...

    2. Re:I'm in a slightly similar position myself... by Hognoxious · · Score: 1

      It's quite possible to stuff a raviolus (or whatever each individual unit is called) with spaghetti.

      I've seen it. And probably done it.

      --
      Confucius say, "Find worm in apple - bad. Find half a worm - worse."
    3. Re:I'm in a slightly similar position myself... by PortHaven · · Score: 1

      Yes, you are quite right. I apologize to my Italian heritage for my typo.

      And that's Mr. Fucktard to you!

      (by the way, what stupid 'tards decided that languages like French and Italian would write letters that they would never pronounce?)

  56. OOP the Spaghetti Code of Tomorrow by PortHaven · · Score: 1

    I am sure that when developers look at our code in 20 years from now. They will refer to it as Spaghetti code. Especially when they work with a lot of the convoluted implementations of MVC inspired frameworks. They'll wonder what the !@#$% were we thinking?

    They'll wonder why for a simple query they have to create four new templates and modify a 1/2 dozen more. They're wonder why there is no reference guide to link to these. And how they're stuck following a trail of breadcrumbs. They'll be flabbergasted to think that we thought we were somehow decoupling things when in fact we greatly increased the interdependence of files.

    Yes, in 20-30 years, our great decoupled object-oriented programming will likely be the spaghetti code of it's day and be viewed as archaic as the use of GoTo logic.

    ***

    And unlike procedural spaghetti code in which one could often follow the logic procedurally. OOP spaghettic code often is so decoupled that it is extremely hard to follow or discover what and where something may be called from if you do not have some sort of road map.

    And let's be honest, do you really think our usually poorly documented roadmaps for our OOP apps will be existent for the developers in 20+ years?

    Do you really think there was no documentation whatsoever for all these applications written in COBOl six decades ago? Back when it was almost standard to first write a PSEUDO code version of an app.

    No, we just tend to be more arrogant because we're "uptime"...

    1632

  57. First THING to Do: by PortHaven · · Score: 1

    The first things to do are the following:

    1. Assess the present stability of code? Is it for the most part functioning? If there are a handful of critical errors. Address those, but do not get bogged down.

    2. Assess the core requirements. When I worked on a medical practice management application we had tons of requirements. Many of which we were told were ABSOLUTELY CRITICAL to the practice. A year later we'd find out said feature had not even been used once.

    Determine what features/actions are core....re-write these in new code with a critical eye to performance and stability.

    3. Run concurrent systems, transition 90% of core tasks to the new re-written, more extendable and adaptable code. Realize there will be some compromise on perfection in order to inter-operate.

    Leave uncommon tasks to the old antiquated system. Sure it sucks for a user to have to log into the old system 3-4 times a year to run some quarterly task or procedure. But it's something most users can deal with, and will do so with only minimal griping. Especially if the core tasks are now functioning at an improved level.

    4. Road map features and slowly add new feature requests or migrate old features to the new app as is required by user need. Why map an old feature that's used 1-2 times a year if a new feature is needed everyday. Why add a new featured used 1-2 a year if an old one that is used weekly can be migrated instead.

    5. Enjoy the fact that you're not unemployed and homeless. Yes, the guy who posted up above exclaimed he'd rather be homeless. But I wager most people are smart enough to know that undesired homelessness without a support system sucks. And would prefer NOT to be there.

  58. Don't start until you have these answers by cpslash · · Score: 1

    Don't start on a 200k spaghetti code base until you have satisfactory answers to these questions: #1 - Is the code under code management such as svn, git, or cvs? #2 - Do you have a proper bug and new feature reporting system?. #3 - Does anyone know how are changes/deliverables managed? Is the sales force out there just selling willy nilly? (Don't laugh, please, I've seen it.) #4 - Does anyone do Q/A? #5 - Are you being given a raise for this new responsibility? #6 - What possible career advancing goal do you meet by picking this up? Most likely its working with dead code, on a dead ship on a dead sea. #7 - Does your manager want you to deliver at the same rate as your predecessor? #8 - You talk to your boss about hiring someone and restructuring the code base, but he says there's no money or head count. He just wants you to 'fix' it up. #9 - Do you have to meet once a week with some marketing fool and explain why you haven't met their unrealistic milestones? #10 - Did the last guy go because he had a heart attack? If so, do you want one?

  59. A real-world answer by whitroth · · Score: 1

    200k lines is big, but not impossible. The real problem is what some subject matter expert coded 12 years ago, who left 8 years ago, and no one's looked at since, because everyone's scared of it.

    What a lot of folks in the comments I've skimmed utterly ignore is that this is a "complex chemical processing plant". If slashdotters code crashes, oh, well, they get yelled at, and it gets fixed.

    With a chemical plant, not quite the same. Think of the disaster in Bhopal, India , or the last major oil refinery fire.

    The way I'd deal with it is this:
    0) Identify one, or preferably more than one, subject matter expert in each area of the plant
    covered by the software.
    1) it's 10-20 yr old *spaghetti* code. Document it. ->Do flowcharts-. (And if you kids look down
    on them, that's because you don't understand a toolbox larger than 1 hammer and 1 screwdriver,
    and if I were hiring you, you'd be as junior as it gets). *THEN* you have some idea of what's
    happening, in what order.
    2) Bring in the subject matter experts for a working meeting, with very high level diagrams, and let
    them figure out what section of the code, and process, they know about.
    3) Set up meetings with individual subgroups, and get lower level flows - the code should relate to
    the process in the plant, which presumably starts at one end, and various things come out
    at various points
    4) Identify where stuff jumps the line, and whether it actually does that, or whether that's a major
    problem.
    5) And pick a common language that's stable, going to still be common in 20 years, has a *lot* of
    folks making a living in it now... and one that's close enough to G2 that the people you have
    to work with, who'll probably be there long after you're gone, will be able to transistion to
    easily, without a lot of resistance. Since you're saying Pascal w/ graphics, I'd suggest an
    older language - C, or C++ - I promise you'll have a lot of problems with Java, and as for
    current fad languages.... I do think you'll really, really want a *compiled* language, for
    something like this, not a scripting language.
    6) Now you're down to normal architecting: : des

  60. Re:*Wooosh* by maxwell+demon · · Score: 1

    Double whoosh.

    You may want to read the replacement comment I suggested. It does tell you even less than the original one! And I "justified" it with common wisdom!

    (Somehow I fear you really thought my code comment was a good one ... in that case, please tell me how to avoid software you've written!)

    --
    The Tao of math: The numbers you can count are not the real numbers.
  61. Definietly take small bytes out of the code ... by FreedomFirstThenPeac · · Score: 1

    Exactly. If at all possible, build a test suite of data that exercises the old program, then make sure the newer versions give identical answers and if possible, generate random data as well to find logic that does not exist except by chance. Don't know how you could do this if your are talking about a GUI program, I am thinking of engineering type problems.

    --
    "There is no god but allah" - well, they got it half right.
  62. Don't believe it... by cwsumner · · Score: 1

    Many people will tell you not to upgrade old applications. It's not worth the trouble and it's much easier to just write a new one, right?

    Wrong! (usually)

    No one likes to endure the "learning frustration" of figuring out someone else's code. particularly several someone elses. But there is knowledge in that old code that no one else knows, and functionality that no one knows about. Except your customers, who will complain vociferously!

    Writing a brand new Application will cause the loss of functionality. It will very likely cause the loss of operability, because there are things that you don't know, without which the app will not work.

    In the last year, I have seen this happen to two separate hardware manufacturers, whose "smart" products we have to use. I have also had it happen to me once, a long time ago before I learned better. It has also caused more than one company to go out of business!

    Be warned. The hard way is often the easy way, in the end.

  63. Entirely possible by Dabido · · Score: 1

    I once worked for a company that had code that had started being written in the 1960's that they had continued to build on that was all spaghetti. In the late 1990's they decided to un-spaghetti it. At one stage I was given four programs (all spaghetti, no documentation) to work out what they did and rewrite them. They came to 10,000 lines of code. I managed to do it in 2 weeks. (This doesn't include the code review by three other programmers or the testing by the testing department to have them sign off and agree it all worked. It didn't require any changes or rewrites, so was good code). So, someone working at the same pace could theoretically complete the task in 40 weeks. Of course, this doesn't take into account the complexity / obfuscation of the code. But 200k lines of spaghetti at it's worst, maybe a year and half for a lone programmer to complete (taking into account program code reviews and testing etc).

    --
    Sure enough, the cow costume was hanging up next to the superhero outfit and sailors uniform. (S,Spud)
  64. 200k lines of code what to do. by lsatenstein · · Score: 1

    If it was my task, I would first make certain that I had a copy of all the source and that if at all possible, using a test system, recreate the production executables.
    You may have to do this while "maintaining" some of the known critical code via bug fixes". Until you have a working test system that matches the production system, you will never know if the code you have to maintain matches the production, is used, or was never deleted because it was a "Just in case... copy".

    Thereafter, were I doing it, I would implement some change management procedures. Any change request has to be in form of a request, with a justification. This cm process will help you get a handle on the business priorities. I can email a cm form.

    If you can get a college student or intern to help you out, go for it. Your job is going to need help, and a project of this size is just right for a one semester project.

    As you put source code together that are related into separate directories, (you are organizing the sources), your task may suddenly not appear as bad as you thought. Do not think of the coding, but concentrate on the business processes, and most certainly, visit the end-users to find out when their subsystem was implemented. Try to match that with source dates or comments within the sources. Organize your directory names for the business processes,

    Please note, you cannot do it all in a day. It will take about 16-20 weeks of dedicated work to complete the cataloging and getting a proper handle on the business application.

    Best of luck.

    --
    Leslie Satenstein Montreal Quebec Canada
  65. Re:Don't put up with it. by Thuktun · · Score: 1

    Major rewrites should only come when the cost of adding necessary new features exceeds the rewrite by some margin.

    If you're lucky, you can build something with an identical interface that lends itself well to automated and manual testing of features to ensure all of the features get implemented. If you're not, you have to dredge up requirements from years of bugfixes and enhancements to ensure that you're covering all your bases.

    Stepwise refactoring is usually much easier and safer than rewriting something.