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!'"

236 comments

  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 Anonymous Coward · · Score: 0

      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.

      Ahahahahahahahaahaha!!!!!!!!

      Good luck with that you fucking noob.

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

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

      Like Debian Stable, you mean?

    17. 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.

    18. Re:...no by amirishere · · Score: 0

      You do realize that a distribution with new features that only updates for bug fixes is a sort of a paradox? Anyway Debian Squeeze was released on Feb 2011 so it is quite new.

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

      Isnt this how Netscape died?

      According to Joel Spolsky...

      --
      geek. lawyer.
    20. 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.

    21. 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.

    22. 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?

    23. 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.
    24. 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?

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

      Fair enough. Thanks for the correction.

      Do you use Debian Stable?

    26. 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).

    27. 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.

    28. 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.

    29. 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.

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

      "Do you use Debian Stable?"

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

    31. 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.

    32. 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
    33. Re:...no by Anonymous Coward · · Score: 0

      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).

      That makes it even more likely that there are non-obvious side effects and dependencies buried in there. Even for a maintenance-only role I'd want mad regression tests set up to valid any change at all.

    34. 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.

    35. Re:...no by Anonymous Coward · · Score: 0

      Given the summary, documentation doesn't appear to be the issue:

      " inherit 200k lines of 'spaghetti code' cobbled together over the course of 10-20 years"

  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 Anonymous Coward · · Score: 0, Redundant

      This. The worst impediment to productivity is not lack of "processes", but idiots who don't know how to do the job so instead try to tell other people how to do it.

      Good developers know how to untangle (or simply reimplement) bad code. And then they document their work going ahead. They with their team develop a method to suit the particular application.

      If someone says something like "agile" or "extreme" or "rigid" or "process" or "productivity" then you know that they're interested in everything but actually getting the job done. In the best case, they're just trying to make some money for themselves. In the worst case, they actually believe what they're saying. "Efficiency" drives in the public sector are even worse than in the private sector, FWIW - targets are always simplistic and their achievement does not necessarily mean that things are working any better than before.

    2. 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.
    3. 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

    4. 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.

    5. 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?

    6. 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.

    7. Re:Farm out OP writing, too. by Anonymous Coward · · Score: 0

      staples sells them, office depot, even newegg. Googled for it, so it may be online-only. Although... I'd probably purchase the paper at a local store rather then shipping the heavy buggers...

    8. 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.

    9. 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 Anonymous Coward · · Score: 0

      Linux is pretty well-written and widely documented (because so many people use it). Compare it to some first year CS students' project code and you'll see what I mean. Extrapolate the latter to 10-20 years of development: that is spaghetti code.

    2. 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.

    3. 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.

    4. 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.
    5. 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.

    6. 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".

    7. 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.

    8. 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.

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

      The Windows kernel is, of course, about 2.2 Mb of undocumented spaghetti. It's been a mess since Dave Cutler threw a demo together that Gates shipped!

    10. 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."

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

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

      The really frightening thought is that there are many female first year CS students...
      The really frightening thought is that there are many black first year CS students...
      The really frightening thought is that there are many asian first year CS students...
      The really frightening thought is that there are many gay first year CS students...
      The really frightening thought is that there are many teenage first year CS students...

      see, no matter how you put it, it just doesn't get any better...
      How the fuck did this get marked Insightful?

      Here's an idea... that 40 year old potentially brings with him something that most software developers lack... experience in an industry other than IT that just may be crying out for a killer app that no-one else has the knowledge or foresight to see, and a work ethic to go with it... after all, they bit the bullet and went back to school at 40 - you don't do that on a whim.

    12. 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.

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

      All that is required to a redesign of the code in parallel with the current production code. After 3-6 months the entire system would be rewritten and tested to the point it could move into production use thereby replacing the spaghetti-code version. I have inherited such spaghetti-coded applications, utilities, etc. over the years on various projects that without exception a complete redesign was necessary but at the same time the existing system had to be maintained in the short-term.

    14. 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.

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

      You misunderstood his post, you tard. He meant there are 40 year olds that still code as if they're first year CS students. He had nothing to say about 40 year old people starting CS first year. Get your head out of your ass before jumping at someone for a post you didn't bother to understand. Probably because you're a 40 year old only now doing your first year CS degree.

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

      Unfortunately, he's still managing a medical device that impacts peoples' lives, and his code is still shit.

      Isn't this the kind of situation worth blowing a whistle at ?

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

      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.

      How did you know "Spaghetti" was the code name for Windows 9?

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

      You misunderstood his post, you tard. He meant there are 40 year olds that still code as if they're first year CS students.

      Perhaps if your (sorry, his) post had been better written he wouldn't have misunderstood it? Your claimed meaning isn't the one I would have chosen, and apparently I'm not alone. The phrase "weaseling out" springs to mind.

      Probably because you're a 40 year old only now doing your first year CS degree.

      Why is that a bad thing? Some people don't have trust funds, or do time in the armed forces, or just recognize the usefulness of education later than others.

    19. 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."
    20. 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. Obvious by Anonymous Coward · · Score: 0

    Rewrite from scratch.

    1. 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.
    2. Re:Obvious by Anonymous Coward · · Score: 0

      While this is very likely to be the worst solution, it will fortunately also probably be very hard to sell it.

      FTFU

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

    Outsource it to India!

    1. Re:Easy! by Fuzzums · · Score: 0

      Yeah. A phryd y cewch eich cod yn ôl, bydd angen cyfieithu google i ddarllen eich sylwadau ;)

      --
      Privacy is terrorism.
    2. Re:Easy! by Anonymous Coward · · Score: 0

      You can spot Welsh from a mile away :P

    3. 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.

    4. Re:Easy! by Anonymous Coward · · Score: 0

      Especially when they have Heddlu on ttheir front/back!

    5. 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
    6. Re:Easy! by rbrausse · · Score: 1

      Welsh

      while drunk

      this is synonym, isn't it?

  6. in my experience... by Anonymous Coward · · Score: 0

    ... it are usually the bad and inexperienced programmers who upon taking over a project condemn the existing
    code to be a mess and wanting to do a rewrite.

    1. Re:in my experience... by Anonymous Coward · · Score: 0

      No surprise.
      1) the bad and inexperienced programmers make up the majority of programmers in the world.
      2) because most programmers are bad, most projects also end up being a mess.

      And 1) is why rewrites usually don't work either. The other reason is even good programmers usually have no time to rewrite everything. Everybody cares about new features, only a few care about old bugs that they grumble about but have lived with for years - until the system gets pwned...

    2. 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.

    3. Re:in my experience... by Anonymous Coward · · Score: 0

      .. it are usually the bad and inexperienced programmers who upon taking over a project condemn the existing
      code to be a mess and wanting to do a rewrite.

      I'll bite.
      Firstly, I'm technically out of the IT game now, but money is money, so I still do the occasional paying IT job. I'm currently debugging some Perl code for a client, I'm about 1/10 of the way through, and I've found two major howlers so far;
      1. a block of 30 lines of code called in such a manner that it occasionally processes an intermediate data file before that data file is fully populated/generated, and it does so in a somewhat quasi-random manner, leading to all sorts of unpredictable fun and games later on in the code and the eventual output files. (whilst I've been typing this, I've been debugging the most recent changes I've made to fix this..and probably will be doing so for the next week).
      2. a failure to check that a number of these output files already exist means that it regenerates needlessly 5,400 files every time it runs (and this number increases weekly), increasing the code running time by a significant factor (fair amount of number crunching and graphics generation involved). Fixed that one yesterday, that was trivial..so trivial, in fact, that even a tyro programmer would have spotted it immediately.

      At this point I'm looking at suggesting a rewrite to the client as, based on what I've found so far and some other suspicious looking blocks of nonsense within the code, I cannot guarantee that any of this code I'm looking at truly works as per the original spec (all nicely documented btw..the spec, that is, not the code - it's the usual 'someone-else's-Perl-hell' ).

      Sometimes it isn't about wanting to do a rewrite, but needing to do so based on circumstances.

      I'm also going to add here, much as the state of the current code I'm looking at pains me, I'll not be the one doing the rewrite if my client does go down that path, I'm just identifying/fixing the problems with their code that they already knew was faulty from the anomalous results it occasionally produced , I'm not massaging my ego/whatever by 'dissing' the existing code as being 'messy' or inadequate for the sake of it..it just IS.

      Ach, I'm off for a cup of tea...EOR.

    4. 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.
    5. 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
  7. Why? by Anonymous Coward · · Score: 0

    Is it broken? Why does he need to fix it?

    1. 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.
    2. 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.

  8. Don't put up with it. by Anonymous Coward · · Score: 0

    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.

    1. 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.)

    2. 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.

    3. 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.

    4. Re:Don't put up with it. by Anonymous Coward · · Score: 0

      >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?

      Ah, what I wouldn't give to be young and naive again. For him and the industry noobs who modded him up, "my boss really doesn't care" means exactly that: it's work that must be done but is not high on the attention list of your management chain. Doing a good job will not be rewarded but doing it poorly will have unpleasant consequences. Sustained engineering work is a common example.

    5. 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.

  9. 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 Anonymous Coward · · Score: 0

      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.

      For a legacy application with no written specifications, I'd say you're short by about a year.

    8. 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.
    9. Re:Rewrite it by Anonymous Coward · · Score: 0

      You have to consider efficiency. Spaghetti code has massive amounts of duplication because the 'developers' don't use any of the features of the programming language to keep the amount of code to a minimum. These 200k lines might represent 50-100k lines of well written code.

  10. 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.

  11. 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: 0

      all bow to the arrogant one preaching humility!

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

      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?

      I'm the guy trying to shoe-horn some piece of *new* functionality into 200k lines of crap that works without costing our 10,000 clients, and subsequently, our company hundreds of thousands of dollars because we put out a bad update.

      Forget the chemical plant... fuck the chemical plant. Lets go back to basics and make it a car.

      As a designer, if you want to prototype a car and try all sorts of crazy shit to make a better car, knock yourself out... break the rules. forget rules.

      But if you want to put that car into mass-production, advertise the living crap out of it, sell shitloads of them, and then bring out the update model in 2 years and repeat the process over and over... then you'd better know what your're building, how you're building it, how you're *required* to build it due to a multitude of 3rd parties, and how you plan on supporting 10,000 of them out on the road with other cars without getting sued - and you'd better know how to pass that information on to someone else.

      Almost everything *new* is following in the footsteps of something else. That guy working for Google is relying heavily on the image processing work done by people before him... if nobody documents what they do, nobody learns.

    4. 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.

    5. 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.

    6. 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.

    7. Re:1. Lose the attitude by angel'o'sphere · · Score: 0

      People should stop moding ACs to +5 insightfull first off all: the mod points are completely wasted, no one gains karma! And secondly, as soon as the first one gave him +1 other modders blindly follow.
      E.G. Step 2)
      What has understanding the codebase to do with a process of refactoring? NOTHING! Refactoring old code to your new desires only has 2 dimensions: programming language and programming paradigm. E.g language: C, fortran, 4gl; paradigm: structural, oo, functional.
      The conclusions in the following "steps" are the same nonsense, it does not look that that AC has any clue about refactoring/rewriting or software production at all ...

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
    8. Re:1. Lose the attitude by Anonymous Coward · · Score: 0

      Pet peeve: what exactly is "test-driven" development? Tests driven by requirements, so by the transitive property it shouldn't be called "requirements-driven" developement? And isn't that what the industry was doing 30 years ago?

    9. 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.

    10. 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).

    11. 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.

    12. 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.

  12. A meal fit for a programmer. by Anonymous Coward · · Score: 0

    How To Deal With 200k Lines of Spaghetti Code

    Well some good spaghetti sauce and a nice wine.

    1. Re:A meal fit for a programmer. by Anonymous Coward · · Score: 0

      You misspelled 'whine'.

    2. 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
    3. Re:A meal fit for a programmer. by Anonymous Coward · · Score: 0

      And don't forget a table with some dining philosophers !!

  13. 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.

  14. Write a program that rewrites the code by Anonymous Coward · · Score: 0

    Use basic AI procedures. Remember that simulations of the code will be necessary for the re-write. Also, the result might be too complex for humans to understand. That's no worry, just have a sandbox ready where you can simulate stuff.

    1. 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.

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

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

  16. 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 Anonymous Coward · · Score: 0

      Fire some barbs at the management who let become this way. The peopel you crossed the cost/benefit line, and made those decision need to be personally accountable, not some crap that the IT boys are lazy and not up to the challenge.

      Bring in the big names to see how much a rewrite will cost. Let those number fly.
      Going to look good, manage on this and pay this much, or rewrite and pay 30-50 times more for something with less functionality.
      Unless the message short term slash and burn does not pay in the long run, they will treat you like a walmart droid.

    2. Re:Don't touch it by Anonymous Coward · · Score: 0

      Sort of agree.

      Although I often see that a large project reaches a kind of homeostasis wherein the most painful bugs and missing features are gradually fixed by the aforementioned gradual improvement process, but the lesser bugs and annoyances are kept in forever because people get used to working around them, and fixing them might entail re-writing a lot of the now 'good' parts for uncertain results.

      And it's a very important process, the incremental improvement loop: In most real-life deployments there are things couldn't be taken into account beforehand, experience that needs to be gotten before a version 1.1 can be made..

    3. 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...

    4. 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.

    5. Re:Don't touch it by Anonymous Coward · · Score: 0

      There is a book about this:
      Working Effectively with Legacy Code
      The summary doesn't give many details, but the situation is different if you have to add features, or just do bug fixes.
      Or if you get specific orders to do something with it.
      Like you said I'd just rewrite only the parts that are needed for some reason and leave the rest alone.

    6. 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.

    7. Re:Don't touch it by Anonymous Coward · · Score: 0

      Good idea! Nothing helps your career quite like "firing some barbs at the management". While you're at it, explain loudly to everyone within earshot why you are a genius and how stupid they are!

    8. 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.

    9. 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.

    10. 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();
  17. 200,000 lines ISN'T THAT BIG (rewrite)... apk by Anonymous Coward · · Score: 0, Insightful

    Try projects of "enterprise class" that span into the MILLIONS of lines of code.

    * I'm serious here...

    Yes, there's a BIG difference between walking into a system with 200k lines (this is REWRITE territory still imo, & it's a professional one with over 17++ yrs. & around 30 projects of the MILLIONS OF LINES sized code for information systems)

    vs.

    One with millions of lines in it (not so simple to just rewrite).

    APK

    P.S.=> There's a time to rewrite, and a time not to, and when you're sub 500,000 lines, a rewrite IS possible and if it is as "bad" as this article *tries* to make it out as, then you rewrite when it's THAT small (& yes, 200k lines is TINY)...

    I've done my assessments here based on doing smaller stuff from:

    ---

    1.) The shareware/freeware level (most of mine here maxed out at around 5,000 - 10,000 lines of code tops)

    2.) Commercially sold code in utilities I am part of in THAT market (usually midrange size 10,000 lines - 100,000 lines)

    3.) Finally, and yes, "Enterprise Class/Industrial Strength/Mission Critical" information systems (these had millions in front end code alone, toss on SQL Stored Procs & more? You get the picture!)

    ---

    The latter's where I've made the largest part of my livelyhood professionally since 1994 ( these definitely can often be quite large into that MILLIONS of lines of code range, with MANY "moving parts" in libs, main code, SQL stored procs, and tables/devices on DB's galore + more)...apk

  18. You need to break the problem up into chunks by Anonymous Coward · · Score: 0

    Take bits of the code and rewrite them one by one. Tackle a function here and a function there and over the course of a few years you'll have 400k lines of spaghetti code since modern coders don't need to worry as much about memory limits and processing constraints.

  19. 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.

  20. Sequence Diagrams by Anonymous Coward · · Score: 0

    Make sequence diagrams based directly off the code.
    This will make your life so much easier.

    Then have a separate project that you rewrite.
    If you aren't being paid to do this and you just want to do this because it is awful to work with, spend maybe 2-5% of your time a day doing it.
    Even do it at home if you wish to. (this is more of a case of if you live and breath programming as to whether you would want to or not. I would)

    But make sure that you let your boss know how great a job you done since most likely that recode will boost the speed and efficiency several times over when you replace the old file(s).
    That will likely get you a big fat bonus or possibly even a raise since you never went and asked for any resources to do it in the first place. Forward thinking people are always loved in business. (unless your boss is a really terrible, horrible person, which most actually surprisingly aren't when it comes to this, most are just the horrible person part)

    Obviously make sure to do your usual project coding stuff as well, documentation is key here since the entire thing became a mess likely because of poor documentation
    The problem now is the others, which the first post on the SO link describes how to deal with very well. (really well in fact. I like that guy)
    It is going to be long and hard, but there is a very good opportunity in it for you if you handle it right.
    Good luck.

    1. 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. 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.

    4. Re:200K Lines not that much by Anonymous Coward · · Score: 0

      I agree with the parent. Don't rewrite it, examine it, get used the style (or styles) involved. Document whatever you find as it will help you and the person coming after you. Rewriting will be a huge pain, it will introduce new bugs and it will take a long time. Try to make small (if any) changes, polishing little things as needed. Don't go looking for trouble by re-writing things, that almost always leads to disaster.

    5. Re:200K Lines not that much by Anonymous Coward · · Score: 0

      Did you even bother to RTFA before dispensing your "wisdom"?

      1) "a fairly small shop of scientists who have spent the last 10-20 years cobbling together a vast code base. The program itself is a physical model of a complex chemical processing plant; the team that wrote it has incredibly deep domain knowledge but little or no formal training in programming fundamentals." Getting your head around the modules is exactly as big a problem as it seems.

      2) "They have asked me to begin presenting to the team some of the principles of modern software development. They want me to introduce some of the industry-standard practices and strategies regarding coding conventions, lifecycle management, high-level design patterns, and source control." So, working on the code isn't even the question.

      3) "(It was written in a virtually obsolete language: G2—think Pascal with graphics)." Not really guaranteed to have step through or other modern debugging amenities.

      4) See 1.

    6. Re:200K Lines not that much by angel'o'sphere · · Score: 0

      Either it is spaghetti code, or it is modulized, isen't it?
      Both things together would be an oxymoron ...
      The rest of your post makes sense, though.

      --
      Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
  22. Abject terror! Rewrite or leave alone. by Anonymous Coward · · Score: 0

    The trouble with really bad spaghetti code is that, if you change anything, something else will break in an unpredictable way.

    The good thing is that you don't have to re-write the code in its original language. If you can use Python, the resulting code will be much smaller (as much as 90% smaller).

    You can also use tools (Simulink, Matlab) to avoid actually writing code. Some industries are standardizing around model-based design. It's a good way to visualize, create and document complex code.

    If the spaghetti code is a maintenance problem, it is costing the company money. You can make a strong economic argument for re-writing it. If the code isn't causing a maintenance problem, leave it alone.

    In the above, I have assumed that the code is truly bad. If it isn't that bad, you should refactor. link link

    1. 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?

  23. Agreed (we think alike & have BEEN there) by Anonymous Coward · · Score: 0

    http://developers.slashdot.org/comments.pl?sid=3026933&cid=40885035

    * I'd look it over, make an estimate of the time needed to get its process/information flows down + a rewrite, vs. sticking a customer with a cobbled-together wreck that rubberbands, paperclips, & superglue are holding together (for now).

    APK

    P.S.=> I average around 400,000 lines of code over 10 - 12 month projects since 1994 on mid-to-large scale information systems (up to "industrial size/enterprise class/mission critical systems into the millions of lines of code)!

    Taking into account you have to get the database schema, information flows, and process down as well, I'd say what's needed is a rewrite here... & it is around 6++ months work, tops!

    Yes - and, of course, money talk$, & it depends on what the client wants & is WILLING TO PAY FOR too.

    Sometimes, those "cob job" maintenence jobs (yes, plenty of those here too professionally in info. systems/db work both as fresh or rewrite &/or maintenance jobs too) are all they can afford, so you are STUCK with it and after oh, 10 diff. guys have worked on it, you get those "spaghetti deals" (which suck to understand even at times) because of money & timeframes... apk

  24. Excellent point - Agree 110% (breakage potentials) by Anonymous Coward · · Score: 0

    See subject-line, and, SO true (on possibility of breakage when doing partial maintenance of code only vs. rewrite from scratch when YOU get full understanding AND full control).

    APK

  25. 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.

  26. 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.

  27. You lucky one! by Anonymous Coward · · Score: 0

    I was hired as a reviewer of a project most members think it's not as bad as it is. Some are professional programmers and the code they write isn't too bad. But not abyssmally bad isn't enough. They started to write code a second time unknowingly as the code is a mess and they don't know about the code. They use the mailing list to compensate missing documentation. They use classes, modules, packages, but the API is sometimes missing or - even worse - plain wrong. The biggest problem - at least some of them think they know what they are doing...

  28. 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.

  29. 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.

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

      > 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.

      You clearly do not understand how a factory works. The output of engineering in a plant is not the chemicals (or whatever) but the plant _configuration_, the same way the output of software development is not the data the software spits.

  30. 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 Anonymous Coward · · Score: 0

      You don't write new tests for correctness of the new code based on your understanding of the old code, you use the old code exactly as it is as a reference implementation of the business requirements.

      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.

    2. 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.
    3. Re:Inexact Results by Anonymous Coward · · Score: 0

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

    4. 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
    5. 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
  31. No idea what the big deal is by Anonymous Coward · · Score: 0

    First, rewriting from scratch is obviously a foolish suggestion. Only somebody completely separated from goals-based performance and the economy of the application would suggest such a move.

    If it is 200K lines of code, it obviously has a fairly wide range of functionality so just tackle it in pieces, rewriting the sections towards a common spec or employing a framework. You'd simply have to allow for extra time for each project, where the development team would simply combine their iterative development of the section being expanded/improved with migration from spaghetti to common form. Where it crossed with other spaghetti, a compromise or facade connection would suffice until everything was brought into line.

    Interface should be the last worry, as a) a spaghetti application is a much more serious long-term drag on any ongoing development, b) the users are already used to the existing interface and c) changing interface means retraining people. Better to build a facade between the existing interface and improved code in the interim, than to have to begin dual-training people on multiple interfaces.

    With a consistent approach, the development team would claw back so much extra time from standardization that those early, extra 'migration' hours would be quickly wiped off the slate.

  32. rewrite from scratch or accept the mantra.. by Anonymous Coward · · Score: 0

    Everybody's code is spaghetti except your own. That is until the next guy see's your code...

  33. They didn't teach you this in college? by Anonymous Coward · · Score: 0

    And I thought CS was trying to be more 'relevant'.

  34. I'd say he meant THIS... apk by Anonymous Coward · · Score: 0

    That's why step tracing of ANY code (spaghetti or not) for a rewrite especially, matters (or even when maintenancing a mess).

    You need to get the programmatic "flow" down, either way. Then, if you're shy of a business analyst? You have to do the legwork on checking the information flows needed (which means investigating db design/schema, and what comes from WHERE in tables in the DB Devices).

    A LOT OF LEGWORK COMES IN WHEN YOU'RE "NEW" TO ANY PROJECT (especially in info. systems work).

    APK

    P.S.=> IF it's a "single module" (possible), then you do what I stated above!

    Which is basically what the poster I replied to here whom you are replying to also, in breaking down said single drop-down inline code (dumb many times, especially for maintainability) that's "spaghetti" into manageable parts/logic engines!

    (Be that functions OR just subroutines/procedures inlined in the SAME module, busted OUT of a single monolithic "driver" main module).

    You then even can separate OUT those methods/functions (or subs/procs, whatever you call them, clarifying what puts out return types (functions) vs. straight 'modules' (procs/subs)) into separate:

    ---

    1.) UNITS (e.g. Pascal UNITS, C/C++ .h headers, or Basic modules ala VB) if need be

    OR

    2.) Even further, into instanceable objects (any OOP languages can do that)

    3.) OR EVEN FURTHER, into custom controls (ala .OCX from VB or MSVC++), or LIBS/DLLS (OLE type or std. type) out of it, and other languages like Delphi or C++ of varying vendor type))

    ---

    Sorry for responding for someone else, but I wager THAT's what he meant... he knows what he's up to, I can tell, as it "takes one to know one"...

    ... apk

  35. 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.
  36. 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.
  37. Better solution by Anonymous Coward · · Score: 0

    Nuke it from orbit.

    It's the only way to be sure.

    1. 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
  38. Re:200K Lines not that much (I disagree) by Anonymous Coward · · Score: 0

    I agree with the idea of using (and the necessity) of having analysts familiar with the legacy coding environment writing business specifications for the existing code (and as well the dependencies between modules) and having multiple developers port it to a new language as a way of moving the code base to something more maintainable. Again, 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) .

    I disagree with the idea that 200k lines not that much. I'd estimate that a better than average developer would be able to read and port between 100 and 200 lines per day, so this project would take between 1000 and 2000 developer days to port. Even factoring in having 5 resources means that this project would take 1 to 2 years at a US cost of $600K to $1200K.

    I would not bother with the rewrite part, I'd focus on identifying the business requirement along with the associated code functionality. The code is maintainable once you know what it is supposed to do and where it does it. I'd also require any changes to be documented to the newer standard. In order to avoid making the problem any worse, I'd put in a SCM, and controls around releases to the production environment.

  39. 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 Anonymous Coward · · Score: 0

      Read TFA. This is a group of people who appear to be interested in getting it done correctly, and understand that the current code is largely unworkable for ongoing maintenance and future enhancements. Although they don't appear to have a clear idea about the best approach to fix it, they do appear to be willing to do things properly.

      They've recently learned some hard lessons about the consequences of nonexistent configuration management. Their maintenance efforts are also greatly hampered by the vast accumulation of undocumented "sludge" in the code itself. I will spare you the "politics" of the situation (there's always politics!), but suffice it to say, there is not a consensus of opinion about what is needed for the path ahead.

      They have asked me to begin presenting to the team some of the principles of modern software development. They want me to introduce some of the industry-standard practices and strategies regarding coding conventions, lifecycle management, high-level design patterns, and source control. Frankly, it's a fairly daunting task and I'm not sure where to begin.

    2. 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.

    3. 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
    4. 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.

  40. don't rewrite by Anonymous Coward · · Score: 0

    Anyone who tells you to rewrite this from scratch should not be working with software. There are no shortcuts. You have 200k lines you don't fully understand. If you try to replace this with a system written from scratch so that you don't have to understand each and every part of the current system, you will fail. It will take years and still never reach a releasable state. Sooner or later you or the guys paying you will lose patience and either scrap the incomplete and misguided rewrite (good) or release it out of fatigue (bad). That is the kind of thing that kills a company.

    On the other hand 200k isn't that big. Live with it for a while until you understand its basic layout, have successfully fixed some bugs and added some features. Then you can start gradually improving parts of it; taking care to understand the code well before you touch it.

    The fact that you do not immediately understand this makes it highly likely that you are not good enough to do this work yet. Find another job where you have less freedom to break things and try to gain some experience.

    captcha: rational

    1. Re:don't rewrite by Anonymous Coward · · Score: 0

      Finally a reasonable, thoughtful opinion. This is the voice of experience speaking here, kiddies.

  41. 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.
  42. done in one hour. by Anonymous Coward · · Score: 1

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

  43. Before you even consider changing code... by Anonymous Coward · · Score: 0

    ...make sure you have a good handle on what's already there.

    I've walked into situations where the application could only be successfully build on the lead developer's machine, and he had no idea why. I've seen teams that were incapable of going through a release cycle without losing some of the new code, and only realizing it when the QA department couldn't get the system to run, at which point the developers had to reinvent what they had lost through sloppiness and laziness.

    First, make sure that you have implemented some sort of version control (even if it is just making regular ZIP files of the source tree until you can arrange something better).

    Second, make sure you can start with a clean machine, load the source tree and development tools and successfully build the application. Until you can reproduce the production version of the software exactly, you don't have it under control.

    Then, you can start worrying about bring order to chaos. I wouldn't try to get anyone to "mend their ways" regarding poor software writing practices right away. I would worry about getting a process in place (write code, check in code, have build machine check out code and build it) to make sure that code is not lost, and that everyone has access to the same code.

  44. 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)
  45. 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.

  46. 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 ).

  47. Depends.. by Anonymous Coward · · Score: 0

    How much are you willing to spend to analyze the problem and construct a plan to salvage what is left!?

  48. *Wooosh* by Anonymous Coward · · Score: 0

    You may want to reread GP.

    In this vein, though, I can also suggest a worthy strategy: comments that allege the code has certain side effects.

    /*Once i is 10, frob a in order to
    override the default masking behavior
    used by the converse invocation of
    this module*/

    ...when no such alternate invocation exists.

    This will imbue the maintainer with a fear of refactoring. Is the code live or dead? Are there other side effects that aren't apparent? Is this a vestigial artifact of a previous refactoring?

    I will admit that this is an advanced tactic that works best in degenerate projects that lack adequate automated testing and SCM.

    1. 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.
    2. Re:*Wooosh* by Anonymous Coward · · Score: 0

      (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!)

      No, but clearly I believed *you* thought it was a good, legitimate comment. I see, however, that you have no difficulty communicating rudeness.

  49. 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.

  50. 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!

  51. 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.
  52. I've had to do this very thing by Anonymous Coward · · Score: 0

    with 150K Lines of 'Yeah, it's done and tested' code.
    The project was almost done by a long term contractor who suddenly left.
    I joined the team and started doing code reviews. This probably had a lot to do with his decision to leave.
    The modiles were almost commentless (bangs head against wall) and full of if then elseif then elseif then elseif etc etc.(bangs head even more)
    Sorting it all out was a salutory lesson to everyone especially the PHB's. It took a lot of time and dedication to fix the damage. Sadly we had to fix it as there wasn't time to start from scratch. Thankfully the old team leader who was supposed to manage the contractor left before I arrived.
    You just have to get on with fixing the mess in whatever way is best for your situation. Don't dwell on the failures that led to the situation happening in the first place.
    A Voodoo Doll in the Effegy of the person to blame with plenty of pins at hand really helps though. Then when It's all over and done you can cremate the doll banishing the bad spirits to the flames down below.

  53. 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.

  54. 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.

  55. 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.

  56. 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.
  57. First... by ChrisLeif · · Score: 1

    Prepare three envelopes.

  58. Modelling by Anonymous Coward · · Score: 0

    The program itself is a physical model of a complex chemical processing plant; the team that wrote it has incredibly deep domain knowledge but little or no formal training in programming fundamentals.

    This is a model of a physical system. Why not raise the level of abstraction and find the state machines from the code documenting the discovery, hopefully at least semi-automatically, to a UML modelling tool which supports the XMI?

  59. 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
  60. 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.
  61. 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
    1. Re:Wrong, incorrectness readily found by Anonymous Coward · · Score: 0

      Or just work with what you get at the company, and make it work for you.

      Code Coverage tools will say if you have exercised all the code, which will give you an idea of if you are generating all possible outputs for all possible inputs.

      If hundreds are eager to find flaws in your output, awesome. Run the systems in parallel during the shake out period, and if the outputs differ then change the new code to compensate it. As long as the new system is not the production system until everyone is happy with the level of flaws, you are fine.

      200,000 LOC will take you about a year at the least. If you can break it into pieces, you'll be able to track progress better.
      This is becoming very common as you can't get fresh grads that know cobol.

  62. Only 200k lines? Lucky! by Anonymous Coward · · Score: 0

    If the 200k lines are utterly horrible, a high-quality rewrite can probably be done in less than a year, with modularity and unit testing kept in mind you can make a high-quality project out of it.

  63. 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.

  64. 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.

  65. 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.

  66. 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.

  67. 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 Anonymous Coward · · Score: 0

      Lasagne. Ricotta.

      Fucktard.

    3. 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."
    4. 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?)

  68. 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

  69. 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.

  70. 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?

  71. 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

  72. 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.
  73. 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.

  74. 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)
  75. 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