Slashdot Mirror


Justifying Code Rewrites?

snow70 asks: "It seems that it is getting harder and harder to justify the decision to re-write rather than hack/patch away on a flawed code base, given the economic situation and the drive to squeeze every last drop out of an existing code base. Are the readers aware of any research articles or reports that extoll the benefits of re-writing in terms of the cost savings in maintenance and support ?" This topic was discussed two years ago, but I think many people who'll find themselves in this situation would also benefit from any research articles or publications as snow70 requests.

47 comments

  1. Yup, it's a dupe by aridhol · · Score: 0, Offtopic

    But at least they're admitting it this time ;)

    --
    I can't say that I don't give a fuck. I've just run out of fuck to give.
  2. Hate to be the heretic... by Violet+Null · · Score: 4, Insightful

    But it's been my anecdotal experience that unless there's a real, justifiable reason for the code rewrite, then it's usually not worth it. Something like taking a client/server application and making it a web application requires a rewrite as a matter of course, for instance, but otherwise the costs and time tend to outweigh the benefits.

    Sure, a code rewrite allows you to remove bad architectural assumptions and dump the cruft, but it also introduces the possibility of an exponentially higher number of bugs. So you've dumped a fair amount of developer work in the rewrite, and then it needs to be followed up with an even more massive amount of QA work. And, if you're actually making sweeping architectural changes, chances are very high that the new architecture will pose some unforeseen problems of it's own.

    I'm not saying a code rewrite is never a good thing, but, IMHO, it's not something that should be done just because "this code is nasty" or "language X is cooler". If you can't think of a reason as to why a rewrite should be done, then it shouldn't.

    1. Re:Hate to be the heretic... by sporty · · Score: 2, Insightful

      It depends on the scale of the rewrite. Rewriting your OS would suck. Rewriting a single library and fixing things via refactoring methods.. it's not that bad.

      -s

      --

      -
      ping -f 255.255.255.255 # if only

    2. Re:Hate to be the heretic... by wik · · Score: 1

      Until you have to replicate the bugs from the old library. Have fun!

      --
      / \
      \ / ASCII ribbon campaign for peace
      x
      / \
    3. Re:Hate to be the heretic... by Rick+the+Red · · Score: 1
      I've found it's best to use new library function names. If you re-write an existing function, then as you say you must replicate the bugs. If you use a new name, you can slowly migrate code to the new functions while still using the old functions. I know of one commercial product that introduces any new function into their production library one release before they start calling it, just to ensure that having it there doesn't break anything. After two or three releases they've finished their migration, but they leave the old funtion in place for one more release, just in case. That way they can always go back to the previous release's (known good) library if they encounter any unexpected problems.

      I discovered this when I asked how to do something and they said "That's in the next release" and then told me how to access this otherwise dormant code in the current release. But they warned me the feature could disappear if they had to revert to the previous library.

      --
      If all this should have a reason, we would be the last to know.
  3. Cathedral and the Bazaar by PeekabooCaribou · · Score: 3, Interesting

    From The Cathedral and the Bazaar, by Eric S. Raymond:

    "... To put it another way, you often don't really understand the problem until after the first time you implement a solution. The second time, maybe you know enough to do it right. So if you want to get it right, be ready to start over at least once [JB]."

    Portions of that quote are borrowed from The Mythical Man-Month. More is available online

    --
    "I'll say it again for the logic-impaired." -- Larry Wall.
    1. Re:Cathedral and the Bazaar by perljon · · Score: 2

      This is why a simple modeling technique is so valuable. I use a simplified version of UML to model my application at different levels of design. This allows me to work out the problem in arrows and pictures instead of in code. Although, it is quite tedious, by the end of a couple of weeks, you can go straight to version 2 of your software. (Where it would take you 2 weeks to model, it might take you a year or 3 to get to version 1. I'd rather spend a few weeks.)

      The drawback to this approach is of course that the client (boss, etc.) doesn't see any 'real' results of your efforts for a while. However, this usually isn't an issue if you set real expectations about your progress.

      about re-write's in general, it's usually more about building something pretty than solving a business need. (you get paid to solve business needs; re-build ugly stuff into pretty stuff when you go home.)

      P.S. there is valuable stuff in the ugly stuff. all those little hacks and bug fixes and logic fixes that happened as a result of customer feedback will be erased.

      --
      This isn't the sig you are looking for... Carry on...
  4. It's good that rewrites are hard to justify! by JonRock · · Score: 5, Insightful

    Point one: rewriting from scratch can be a strategic disaster.

    Point two: rectifying a "flawed" code base can be done within the framework of good software engineering practice, and is a very marketable skill besides.

    1. Re:It's good that rewrites are hard to justify! by jpkunst · · Score: 1

      Point one: rewriting from scratch can be a strategic disaster. [joelonsoftware.com]

      Well, that article is from 2000 and the example that he gives is that is was obviously a bad decision for Netscape to start over from scratch after version 4. But is that still so obvious in 2003? Thanks to that decision, we now have the Gecko rendering engine, Mozilla and all its derivatives, so maybe it wasn't such a bad decision after all to rewrite from scratch?

      JP

    2. Re:It's good that rewrites are hard to justify! by Cuthalion · · Score: 2, Insightful

      Gee, it only took them like 5 years. Could they have made Netscape better in 5 years without starting over from scratch, during which time they lost the browser war and were acquired by AOL? Is Netscape, as a company, successfull?

      I would say the answer is no.

      --
      Trees can't go dancing
      So do them a big favor
      Pretend dancing stinks!
    3. Re:It's good that rewrites are hard to justify! by The+Cydonian · · Score: 1

      But that's only one example of a re-write failure. Opera, if I remember correctly, has completely rewritten its code base for its latest version.

    4. Re:It's good that rewrites are hard to justify! by Etyenne · · Score: 1

      Netscape (actually, Mozilla) rewrite from scratch may have been a disaster from a commercial POV, but from a technical one it is a great success. Personnally, I don't care about the browser war or market share, I care about quality software. That is what OSS is about. Mozilla > 1.0 is quality software. They could have refactored the cruft of Netscape 4 but it is open to debate if they would have had a result as good.

      jwz criticism of the Mozilla project in 1998 may have been justified. Joel rant on Mozilla from 2000 may have been revelant. History prove them both wrong. Mozilla grab the technical lead in 2002 and will certainly continue to hold it for time to come considering his headstart it have and his rapid pace of developpement.

      I don't care about what is popular, I care about the best. Thus I use Mozilla.

      --
      :wq
  5. Refactor by MountainLogic · · Score: 3, Insightful

    Refactor, don't rewrite! First write unit & functional tests then start refactoring.

    1. Re:Refactor by __past__ · · Score: 2, Insightful

      As you say, refactoring relies on having good tests in the first place. Probably a code base that needs a rewrite hasn't been developed test-first up to now, or even in a test-friendly fashion, so that's a huge problem - coming up with good tests after the fact is a lot of error-prone (and boring) work.

      It's probably still a better idea than to start from scratch, though. I seem to remember that someone announced a book on this subject (adding tests for legacy code) on the XP or test-driven mailing list, maybe the original poster should look there.

    2. Re:Refactor by 4of12 · · Score: 2, Interesting

      Yeah...sounds suspiciously like Extreme Programming to me.

      And, AFAICT, that's tantamount to constant rewriting.

      The assumptions are valid, though. Namely,

      software is always improvable.
      Whether it will actually improve under applied effort is another matter.

      If you take the XP approach, then refactoring even at even the highest levels may be justifiable, and if you write in "refactoring" into your XP code dev plan from the get go, then you won't have to write a special, rejectable, proposal for "rewrite from scratch".

      Anyway, the usual motivation for doing The Re-Write has to be when some typical lurking maintainance or debugging chore, or "small feature enhancement" takes a helluva a lot longer than the decision makers like. Sometimes, Joe's a bad programmer is the reason it took so long; other times, it's because Joe was handed a plate of spaghetti masquerading as code.

      If you can say, truthfully, that those exact same debug/feature enhancements would have cost x% less if done within the framework of the hypothetical rewritten code base of the future, then money allocators will do the amortization and figure out if it justifies the expense.

      I'd wildly guess the rewrite shouldn't cost more than about 3 times what annual debug/support/maintenance costs. Others here may know better, though.

      --
      "Provided by the management for your protection."
    3. Re:Refactor by Mr.Locke · · Score: 1

      Martin Fowler has a very comprehensive book on refactoring - Refactoring: Improving the Design of Existing Code (On Amazon)

  6. not B&W by NanoGator · · Score: 3, Insightful

    Sorry to say this, but we don't live in a perfect world. As long as management bases their timelines on when the next trade show is coming up, we're not going to see rewrites happen until one of these deadlines is very badly missed. The people in charge just plain don't care about flawed or badly maintained code bases. They're concerned with getting a product that meets the promises that Marketing made. Sadly, engineers are too good at working within their limitations, thus making rewrites not all that necessary. (As in "we can't launch unless we do that" necessary.)

    I don't think finding articles that show off the wonderfulness of code rewrites will be useful at all. Instead, this topic needs to be made attractive to PHBs out there. Make "total rewrite" a buzzword (you know, like e-commerce, push technology, and multi-media) and you'll gain a lot more leverage than landing a report labeled FYI on your boss's desk. Make it fashionable.

    You all may thing I'm being cynical or even sarcastic, but I've spent the last 6 years watching PHB's work. I've listened to some bizarre rationale. I understand enough about how they work that I could become a cartoonist. I'll be happy to carry the torch when Scott Adams retires.

    --
    "Derp de derp."
  7. Things you should never do... by metacosm · · Score: 4, Insightful
    Rewrite is one of them... Read: Things you should never do

    Let me quote a little from the linked article

    When programmers say that their code is a holy mess (as they always do), there are three kinds of things that are wrong with it.

    First, there are architectural problems. The code is not factored correctly. The networking code is popping up its own dialog boxes from the middle of nowhere; this should have been handled in the UI code. These problems can be solved, one at a time, by carefully moving code, refactoring, changing interfaces. They can be done by one programmer working carefully and checking in his changes all at once, so that nobody else is disrupted. Even fairly major architectural changes can be done without throwing away the code. On the Juno project we spent several months rearchitecting at one point: just moving things around, cleaning them up, creating base classes that made sense, and creating sharp interfaces between the modules. But we did it carefully, with our existing code base, and we didn't introduce new bugs or throw away working code.

    A second reason programmers think that their code is a mess is that it is inefficient. The rendering code in Netscape was rumored to be slow. But this only affects a small part of the project, which you can optimize or even rewrite. You don't have to rewrite the whole thing. When optimizing for speed, 1% of the work gets you 99% of the bang.

    Third, the code may be doggone ugly. One project I worked on actually had a data type called a FuckedString. Another project had started out using the convention of starting member variables with an underscore, but later switched to the more standard "m_". So half the functions started with "_" and half with "m_", which looked ugly. Frankly, this is the kind of thing you solve in five minutes with a macro in Emacs, not by starting from scratch.

    It's important to remember that when you start from scratch there is absolutely no reason to believe that you are going to do a better job than you did the first time. First of all, you probably don't even have the same programming team that worked on version one, so you don't actually have "more experience". You're just going to make most of the old mistakes again, and introduce some new problems that weren't in the original version.

    1. Re:Things you should never do... by ClosedSource · · Score: 2, Insightful

      Any kind of advice that says "Always do.." or "Never do.." is going to be wrong at least some of the time. To state the obvious: not all situations are the same, so you can't treat them as if they were.

      One reason you might want to rewrite a program from scratch is if the effort to understand the code is significantly greater than the effort to understand the problem you're trying to solve. Of course, requirements are an important part of the analysis. If legacy behavior is a requirement (which will typically include behavior that has nothing to do with the actual problem), then that argues against rewriting since you're going to have to reverse engineer the system anyway.

      One should also consider the "do nothing" option. Perhaps the benefits are outweighed by the costs and risks of development.

    2. Re:Things you should never do... by dubl-u · · Score: 4, Insightful
      It's important to remember that when you start from scratch there is absolutely no reason to believe that you are going to do a better job than you did the first time.

      That's true only if you don't plan to do anything differently.

      I recently got called into consult on a project. They have a bunch of code. They need new features by August. Question #1 is, "Do we start over?"

      The current code base mostly works, but it is complete spaghetti code. No architectural coherence, hugely inefficient, absolutely no tests, lots of copy and paste, insane use of exceptions, etc, etc, etc. My first conclusion is that the existing code is totaled.

      But there isn't time to rewrite it all by the deadline and get the new features in. So we compromised with the businesspeople. Working together, we designed the new features in such a way that we touch as little of the old code as possible. Features that required modifying old code got very high estimates, so the suits deferred most of them. Further, all new code will be developed with full unit tests and functional tests, with energetic refactoring so that the architecture is solid. This gives us a good foundation to build from.

      Then, after the release, we'll see what we can do with the old code. Thanks to a highly interactive estimation process (XP's Planning Game), the business people really get that touching old code is expensive. And we've also explained that hacking new stuff into existing code is throwing good money after bad; when asking for those features, they frequently ask how much of the effort can be reused. So they're almost as interested in getting rid of the old stuff as we are.

      So my tips for a rewrite are:
      1. Don't rewrite everything at once. Do it in a way where you can provide a stream of new releases, rewriting as you go.
      2. Make the economic case for a rewrite clear. If you're getting a paycheck for this, you're obligated to help them get the best value for their money.
      3. Don't do the same old thing. Figure out why the current code base sucks, and take clear steps not to repeat their errors. E.g.,
        • write unit tests and functional tests (preferrably before you write the code)
        • continuously refactor your code
        • do code reviews and design reviews (or, better, pair programming).
      4. Measure the difference you're supposedly making. If your bug rates, design metrics, code metrics, reliability of hitting estimates, and performance aren't clearly better than the existing product, then maybe you're doing a rewrite for the wrong reasons.
      5. Be humble. The reason the current code base sucks is that the last chumps got in over their heads. Be sure that you aren't doing the same. Remember, they probably looked at the previous old system and said, "Gosh, we could rewrite this and make it so much better!"
      6. Make sure this is the last rewrite. Sure, future requirements always mean that parts of the app will be changed. But make sure the code never gets so stinky that it needs to be tossed. Every couple of months call in somebody from outside the team to review things and give you an honest checkup.


    3. Re:Things you should never do... by WolfWithoutAClause · · Score: 2, Interesting
      Pretty much agreed; although rewrites of systems can work well in some well-contained cases.

      Generally, In coding (and life in general) problems fall into roughly two categories:

      a) messes inherent in the problem domain

      b) messes you caused whilst solving the problem in the way you did

      Trouble is, most software engineers aren't real good at telling the difference between the two, and usually prescribe 'rewrites' for both of them. If the mess is type b) then you may be able to remove it, albeit often causing different (hopefully fewer) kinds of problems. If the mess is of type a) then it implies that the engineers have missed it; which nearly always leads to trouble in the long run...

      If it's the original team that is involved, a rewrite might be a good idea, but usually it isn't the original team; and even if it is the original team there is a thing called 'second system syndrome' where the designers try to fix every, single, little problem in their first attempt; this usually ends up in a system too large and unwieldy to work well.

      --

      -WolfWithoutAClause

      "Gravity is only a theory, not a fact!"
    4. Re:Things you should never do... by Anonymous Coward · · Score: 0

      There are times when you have to do a complete re-write.
      A company in our market refused to do a complete re-write for years. They had been selling a CP/M based system for years and made lots of money. They sold not only the program but the special CP/M computer that it ran on. The program was of course written in Asm. You had to write in ASM if you only had an 8 Mhz Z-80 to work with.
      That company is not around anymore.
      They waited too long and by the time they had a working MS-DOS program available Windows 95 just around the corner.
      We are planning our next re-write. We will keep the old code up to data while we work on the next version. There are just too many changes we want to make to fit in to the old program We will use as much of the old code as we can.

  8. Sunk costs by Dr.+Photo · · Score: 2, Informative

    Some managers will disingenuously try to use "Return on Investment" to retroactively justify past spending decisions, without regard to whether trying to salvage a poor decision is a cost-effective use of current and future investment.

    ROI should be used as a measure not of how far you've gone, but rather how close you are to your current goal.

    As an example which anyone reading /. will appreciate: Imagine you've spent 8 hours downloading a huge file over dialup, and it's 80% complete... and during that time, your friendly local Telco person has arrived and installed a DSL line that could download the same file in under an hour.

    Which, then, is the better use of your time: to wait two hours for your current download to complete, or to ditch it for the one hour download?

    Of course, as a precaution you might let the slow download continue in case the faster line doesn't work right, just as a company could keep the existing model in operation as a prototype of the new system is developed...

    Companies that can't see this, or that foster a corporate culture in which ROI is used as a retroactive cover-your-ass rather than as an estimate of future costs and benefits, will in the long run be easy pickins for their more nimble-minded competitors.

  9. it's not so much the rewriting by jilles · · Score: 2, Informative

    If you can make a business case for rewriting an existing piece of software, any sane project manager should go for it. The whole problem is that most programming still happens based on hunches & gut feelings. If there's too much money like before the .com crisis, you can afford to aimlessly optimize pieces of code like that and get away with it. However, in the current economic situation, people are not handing out money anymore. You have to convince people to do so.

    Delivering a piece of code on time with the desired level of quality still boils down to black magic in many organizations. A large percentage of software projects either fails or delivers something different than was intended.
    People have noticed this and telling them that you'll lock yourself up, hack away for a couple of weeks and maybe something good will come out does not do the trick anymore. They simply do not trust you to deliver what you claim you can deliver anymore.

    Of course that doesn't mean you shouldn't rewrite code. You should however, make more of an effort to provide evidence to the relevant people that a) there is a problem with the code that should be fixed (e.g. bugfixes take an unusual amount of resources on that part of the code) b) you have a plan for resolving this problem (e.g. spending two weeks on refactoring) and c) this plan is cost-effective (this is the hard part).

    I've seen a project where it was calculated that fixing the outstanding 100 or so bugs for a component (serious bugs) would cost a certain amount of money. This process was likely to introduce more bugs of the same serious nature (given experience with maintaining this component). An alternative was to redesign and reimplement the offending component, a plan was made to do so and it was approved because executing the plan was shown to be more cost effective than continuing to maintain the old component. The plan was executed and the new component has so far proven to be more reliable and maintainable.

    --

    Jilles
  10. Refactor by neitzsche · · Score: 4, Insightful

    I am a sold on the concept of refactoring instead of completely rewriting.

    About four years ago, I rewrote a 15 year old device handling sub-system. It was quite horrible. The primary justification for doing it was to generate billable hours to charge the government. The secondary justification was because the old code was horrible, nightmarish and impossible to maintain.

    Unfortunately, I didn't get the opportunity to redesign the legacy file structures it used. I also had to maintain 100% backward compatability. On my personal agenda was adding useful features. In hindsight, if we had used the refactoring approach the end result would probably hve been better. Certainly the beta testing would have gone smoother if it had been done in smaller increments. (Having a non-technical manager didn't help either.)

    With that experience behind me now, I recommend two things to justify a major piece of work (either rewriting or refactoring):
    1) Identify the current design flaws
    2) Identify the features missing

    These days, the only time I'm presented with a rewite opportunity is when an application is being migrated to a new platform. i.e. Web enabling a legacy app. The only applications that remain out there are still there because they are too ugly, outdated and nightmarish to maintain. So once again, I would recommend refactoring.

    Don't be mad at management for being gun-shy when they hear the word "rewrite." They should be leery of a major rewrite. The end-user training costs alone can be devastating. And unless we're talking about your own personal copyrighted intellectual property, they do have a lot vesting in the old "ugly" code that they (rightly) should be scared of losing.

    --
    "God is dead." - Frederik Nietzsche
  11. Typical geek. Focus on the business problem. by (H)elix1 · · Score: 2, Insightful


    I'm not going to touch the refactor/rewrite issues, because the fundamental problem is you are not effectively giving yourself enough time to do whatever the hell you want to do. Take what time you think it will take to implement something, double it, and round up to the next unit of measurement. Odds are the business does not give a rat's ass about the wrong or right way to implement something anyhow. Why confuse them with options?

    How long will it take to fix this? (keep the snicker internal) Two weeks...

  12. Do you have time? by bscott · · Score: 2, Informative

    I'd like to rewrite most of the projects I've worked on, especially one in particular which gets used and re-worked year after year. A ground-up reworking of the code would make future changes hugely easier, but instead we spend vastly more time trying to force more cruft on top of the massive pile of cruft and hoping it'll work. Even when we start six months before the usual time-frame, we always - ALWAYS - end up making modifications right up to the time it goes live. (I've actually had to recompile a program on a laptop, while in the car heading to the install site!)

    I found the comments of the first few posters to be insightful, but there's at least one situation they overlooked - what if the code is crummy for perhaps the most common reason of all: insufficient time combined with constantly changing requirements? In that case, given time to really do things right could make a difference. Taking the pressure off lets you actually design BEFORE you code, instead of doing them in parallel, and you might even get to shift some of the user interface planning off onto someone qualified to do it... (I've never had the pleasure of working within a team on a project, BTW, so YMMV. Oh, and I've never had the pleasure of working on a project where there was anybody to say "no" to the customer's latest wacky, impractical, last-minute ideas...)

    OK, where were we - oh yes, I'd like to hear the answer to the poster's question too.

    --
    Perfectly Normal Industries
    1. Re:Do you have time? by hswerdfe · · Score: 1

      sigh....I had to Call the office from on site to get a recompile and have someone ftp it to me, because the install failed....our company sucks...we have NO qa department...

      --
      --meh--
    2. Re:Do you have time? by dubl-u · · Score: 1

      insufficient time combined with constantly changing requirements? In that case, given time to really do things right could make a difference.

      Every project I've ever been on has insufficient time combined with changing requirements. I'm not even sure if I've heard of a project where that wasn't the case.

      Given that, I think it's our responsibility to create the necessary space to do good work. Now I only offer clients two options. One is building 100% solid software. The other is building cheap, throwaway prototypes that come with absolutely no guarantees.

      As far as I can tell, there's nothing in between. Software that is allowed to be only 95% solid rapidly decays until you reach critical mass. Or, in a lot of corporate situations, you put all your effort into holding together a system that is at the brink of critical mass, leaving you almost no time for improving the code. So if we're going to write garbage, we might as well do it honestly from the start, rather than sneakily or accidentally.

      Now convincing bosses and clients that there are only two options isn't easy. But it's a fuck of a lot easier than spending six months working 60 hour weeks trying to keep a crappy code base together while hacking in features according to a release schedule put together by some blowdried doofus in marketing, whose interest in your wellbeing is limited to hoping you don't have a heart attack before the ship date.

      I've never had the pleasure of working on a project where there was anybody to say "no" to the customer's latest wacky, impractical, last-minute ideas

      You should look into the Extreme Programming practice known as the Planning Game.

      The basic notion is that you break a product down into a bunch of little bite-sized features. Each one of these mini-features, called a story, and is written on an index card. The businesspeople can ask for whatever they want, and the programmers estimate it. If the estimate is more than a few days of work, then suits and geeks collaborate to break it down into separate cards that are just a few days in size.

      Then the suits get to put the cards into a big stack, ordered by their notions of what's most important, and the developers must build them, a few cards at a time, in that order. The suits may designate any point in the stack as a point where the software gets shipped.

      Note the important separation of powers: the suits get to order anything they want. The developers get to say how much it costs. This lets the suits, as they seem to enjoy, have endless meetings about which features get into which releases, while the developers are off coding away on the features that are at the top of the stack. If the business decides that they want to change priorities on stuff a ways down in the stack, that's not a problem; the developers haven't gotten there yet. and if they want to change something already built, that's ok too, as it's a new card that they have to schedule just like everything else.

      Although there's a little more to XP scheduling, that's the essence of it. And it sounds too simple to work. But I've done it on several high-pressure projects, and the business analysts and execs have taken to it every time. They love it, as it gives them complete control over the schedule. And the developers love it, because they're not the bad guys anymore; there only job is to make solid stuff, not to resolve impossible scheduling dilemmas.
      Ok, I'll stop. But if people have more questions, feel free to ask, either here for via email. After years of building software the hard way, I'm absurdly happy that building software doesn't have to hurt.

    3. Re:Do you have time? by bscott · · Score: 1

      > Every project I've ever been on has insufficient time
      > combined with changing requirements. I'm not even sure
      > if I've heard of a project where that wasn't the case.

      I had one, once... fond memories! I actually had all the time I needed and a fairly clear goal. There was even left-over time in the budget to do a second version with some nice new features that the users decided might come in handy down the road. I even was able to write user-level documentation as well as technical docs for any future programmer who might get called in after me. And what do you know - the software worked without a single reported problem, for 2 years, until the function it served was taken over by another agency. (as far as I know it's still in use - they've never contacted me with any questions or complaints)

      Gad, those were the days.... (it was even an interesting challenge on a programming level, as opposed to most of my work which is event-driven GUI-logic-heavy busywork, or struggling against inaccurate Microsoft technical docs)

      > > I've never had the pleasure of working on a project
      > > where there was anybody to say "no" to the customer's
      > > latest wacky, impractical, last-minute ideas
      >
      > You should look into the Extreme Programming
      > practice known as the Planning Game.

      I should look into the practice reported in the Dilbert strip, where the customer refuses to tell him the product requirements and he replies "That's OK, I've budgeted for some goons to beat it out of you." Then again, I've gotten a lot of work cleaning up after messes caused by poor technical decisions. It's just not work I actually like to do... (I remember one in particular where a state government agency had hired a consultant to write an Access database, and the guy turned the job over to his 16-year-old son! The documentation was nonexistant, and I found signs that the system had been modified on at least two separate occasions by people who simply blocked off or disabled chunks of the code that they did not have time to understand and fix... they flew me out twice to look it over and try to make sense of it all, and in the end I just told them it'd be a lot easier to re-implement from scratch than to try to make it Y2k-OK. Never heard back from them after that!)

      If I ever have the luxury of dictating to an employer that design must occur BEFORE implementation rather than in parallel with implementation, I'll certainly seize that opportunity with glee. However, I have never worked for a large company (difficult to get an interview anyplace big enough for a real HR department if you lack a college degree or other credentials - and I have nothing but real-world experience) so I've never been part of a team or any other sort of structure which might help that. I'm usually lucky just to have a job, actually (oh yeah, I don't have one right now...)

      Where was I? Never mind.

      --
      Perfectly Normal Industries
  13. How much pain can you tolerate? by pmz · · Score: 1

    Brooks' The Mythical Man Month reads "...plan to throw one away; you will, anyhow." However, I read this to mean a real working prototype rather than a production system that simply gets tossed. If you are wondering whether a genuine production system needs rewriting, it's probably too late. If you can tolerate the pain, factor where you can; if not, brave the job market for a better opportunity.

    1. Re:How much pain can you tolerate? by geekoid · · Score: 1

      most production code is a prototype that was 'good enough' and 'we don't want you to have to do the same thing twice' and 'well, the developer finished the prototype, so the production model should be ready in a weak'

      --
      The Kruger Dunning explains most post on /. http://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect
    2. Re:How much pain can you tolerate? by pmz · · Score: 1

      most production code is a prototype that was 'good enough'...

      Yeah, I've seen this happen myself. The end result was rather unsavory in the long run. A lot of the problem with software development is that few people look past the next milestone.

  14. How long will it take? by Glonoinha · · Score: 3, Interesting

    I have a pretty good formula for getting the actual time it will take :

    If your coder is just out of school take any time estimates and factor by x5 Estimates two days, it will take him two work weeks. (*)

    Junior programmer with 1-2 years experience on this kind of thing - factor by x4.

    Senior programmer with half a decade or more of experience = factor by x2 or x3 - it varies.

    Any task with a description that starts 'Why don't you just ...' : 3 months minimum, 18 months average.

    Manager says 'It can't be done.' - it will be done by Monday.

    (*) - the reason the Junior guys do this is the estimate how many hours it will take them to complete (which is generally half the number it will actually take) and the math in their head assumes 24 hours of productive time in a day until they finish it. They -could- finish in two days, but they are not going to actually finish in two days. Senior guys recognise that they only get 5 productive hours in a day (on a good day) and divide the number of hours they think it will take by 5 to get days. Of course they also take twice as many hours to get it done, hence the 2x factor for them.

    --
    Glonoinha the MebiByte Slayer
  15. A third way by Waffle+Iron · · Score: 1
    The refactor vs. rewrite argument never ends. However, there is something inbetween the two that I've found useful from time to time: go to all of your source files and comment out all of the code except "main()"; make sure it still builds and executes. Now, start adding back functionality one piece at a time, redoing the parts that need major rework.

    This way, if you're rearchitecting big sections, you don't have to worry about keeping bidirectional compatiblity during the conversion. This approach also works well for porting between different languages.

    However, you're not throwing away your old valuable work either. You rewrite most stuff by editing your old procedures. I usually find that I have huge chunks of code that simply get uncommented again because they work fine in the new incarnation.

  16. don't rewrite, refactor by aminorex · · Score: 1

    If a codebase is sufficiently complex and mature
    so that rewriting raises business issues, you're
    almost always better off incrementally refactoring.
    Take one bug at a time, and resolve it by improving
    design, rather than by adding layers of cruft.
    Formulate end-design goals, and work towards them
    incrementally, preserving all current correct
    behaviours.

    Yes, it takes longer than rewriting, in order to
    achieve 90% of the end goal, but the last 10% is
    always the deal maker or breaker. If your
    codebase is decrepit and complex, you almost
    certainly don't have enough interface definition
    to rewrite a fully functional replacement. The
    process of incremental refactoring allows you to
    simultaneously reverse engineer and document the
    operative interfaces.

    --
    -I like my women like I like my tea: green-
  17. If the by geekoid · · Score: 2, Insightful

    author looked at the code I inherited, he would change his point of view.

    We got a function thats 16 hundred lines long(not countinf white space and comments), it has 5 goto's.

    The person who wrote the code was a self taught programmer. the next person was a self taught programmer with no experience in the language.

    The use 3rd part controls that leak like a sieve.

    there is redundant code all over the place. Comments are lacking.
    there is stuff like:

    If (X = 1) and (X = 1) then

    and stuff like

    while .eof
    if .eof then ...
    loop

    Nothing is generic, so swapping aout the major 3rd party control would entail change 95%
    there a 75 forms, 25 of them identicle.

    Use of the database is incorrect, we got dirty reads happening all over the place.

    This code might be salvagable if there was a design spec in the begining, or any documantation for that matter.

    When it was written there where no specs, and the people working on it had little experience with the industry.

    --
    The Kruger Dunning explains most post on /. http://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect
  18. rewriting rules! by rodolfo.borges · · Score: 1

    if it's worth to write, it's worth to rewrite

  19. To Clarify... by snow70 · · Score: 1

    Actually I am talking about refactoring in this context, a targetted re-write of a core of the application to deliver scalability and stability that the existing 'design' simply doesn't deliver. We are talking about less than 10% re-write, whilst keeping everything that the customer is used to seeing in terms of logs, O&M management etc. However it seems there is little hard evidence to support this process, which to me seems so natural.

  20. Speaking of refactoring ... by gerddie · · Score: 1

    you might be interested in this book: Refactoring: Improving the Design of Existing Code

  21. Clarke's third law of software design by scrod · · Score: 2, Funny

    Any sufficiently patched-up code base is indistinguishable from magic.

  22. Rewrite Experience by CyberGarp · · Score: 2, Interesting

    My first project out of college was to "patch" some computer software. It was written by three different engineers in FORTRAN, working for about 2 years. When it started crashing all the time, the solution was to put a watchdog on the computer. Then it would loose the state of computation, so it started saving it's computation state regularly, and upon booting would restore it. Eventually it saved the state that led to a crash, at which point it started rebooting like a yoyo.

    Looking over the software, it was a total mess. Every section of the code completely reordered all data on the stack, going several levels deep. I asked what the formula the code was trying to compute, and was shocked to see a simple iterative formula, with about 10 variables. I recommended a rewrite. I was heckled.

    I was eventually given one month to waste, before they said I would be forced to patch the existing code. The first thing I did was remove the watchdog. Then I did a data flow diagram and found a straight line. No control over the format of the data going out, but total control of coming in. So presto, I structured the data coming in to match the required format of the output. It would all sit in place and the routines would work on it like a pipeline. It went from taking four or five minutes to do a single pass to nine seconds. It also didn't crash all the time. The size of the code shrank dramatically.

    Two other times in my career I've ran into similar code. The next was about two hundred pages of FORTRAN, that I replaced with one page of lex.

    The next time was a database engine written in FORTRAN by an engineer with no database theory (data/indices mixed, every index was of a different form, every violation of normalization you can think of, etc). I recommend a rewrite then, and just about got fired, because the VP wrote the code. It wasn't rewritten and their competitors have just about squeezed them out of the market, because they can't adapt.

    Lesson: FORTRAN written by engineers is generally in bad need of a rewrite.

    --

    I used to wonder what was so holy about a silent night, now I have a child.
    1. Re:Rewrite Experience by panda · · Score: 1

      I've had similar experiences.

      In one case, a project manager came to me two days before his deadline and said, "Can you look at this? So-and-so was working on it, and it won't run. We think it's there, and it probably just needs a little tweak to get it running."

      Sure, I looked at the code. Turns out what I was looking at was a "translation" of a COBOL app that ran on the mainframe to another programming language that would run on the new UNIX server. The translation was a big, tangled ball of string, actually a giant bunch of nested ifs and gotos.

      I asked to see the COBOL code, and was given a print out. Heh, same giant mess.

      I went to the project manager. I said, "Where are the specification documents for this and who actually uses this program?"

      He swallowed hard and said, "Why?"

      "'Cause I need to rewrite it from scratch. This code and the original COBOL is a tangled mess, and I can barely make any sense out of it."

      So, I was given the documentation and talked with the people in the department that actually used the software, and less than one week later a beautiful example of procedural design was running on the UNIX server, only three days late.

      Sometimes, it does pay to start over from scratch. Sometimes, you have no choice if the code is so bad that no one, not even the person who was originally working on it can understand it. (In this case, the program was being rewritten anyway. I just rewrote the rewrite.)

      --
      Just be sure to wear the gold uniform when you beam down -- you know what happens when you wear the red one.
    2. Re:Rewrite Experience by aaaurgh · · Score: 1

      I used to wonder what was so holy about a silent night, now I have a child.

      Amen to that!

      --

      Go permanent? In your dreams and my worst nightmares.
  23. But..... by samael · · Score: 1

    I'd say that the right thing to do (to start off with, anyway) is to refactor, not scrap it.

    Take that 1600 line procedure and rewrite it more sensibly (modular, no gotos, break it into dozens of smaller procedures). Then do the same with the rest of the code. Remove duplication as you go through. You'll constantly have a system that works and is testable and you'll be able to reverse-engineer the spec as you go through.

    If you tried to rewrite it from scratch, you'd have to analyse the whole thing to see what it did anyway - you might as well rewrite it as you go.

  24. Depends on the nature of the code by Anonymous Coward · · Score: 0

    If the code base is huge (and ugly) and the encapsulated knowledge is large (but the system runs correctly), then I would discourage a re-write:
    Because when you blindly try to rewrite complex business logic you will make many mistakes. You will have to fix them, making your codebase patchy again and probably end up in the same mess as before because you do not have the time to clean things up.
    Refactoring however in this case is the best you can do. Because the logic runs okay you can write test cases for the code you are going to refactor.

    A rewrite is better than refactoring when business needs changed dramatically and the old code does not fit the new requirements at all.

    Also code that is just *completely* flawed (such as written by a completely incompetent idiot), extremely buggy, unstable and not fulfilling requirements is good to rewrite as well.

    The smaller the codebase the better the chances for a successful rewrite.

  25. Plan to throw one away... by Grey+Haired+Luser · · Score: 1

    You will anyway

    Fred Brooks.