The Gamasutra article Dirty Coding Tricks is a fantastic read. One part of it in particular rang true for me.
Consider the load of pain I found myself in when working on a conversion of a 3D third person shooter from the PC to the original PlayStation.Now, the PS1 has no support for floating point numbers, so we were doing the conversion by basically recompiling the PC code and overloading all floats with fixed point. That actually worked fairly well, but were it fell apart was in collision detection.
The level geometry that was supplied to us worked reasonably well in the PC version of the game, but when converted to fixed point, all kinds of seams, T-Junctions and other problems were nudged into existence by the microscopic differences in values between fixed and floats. This problem would manifest itself by the main character (called "Damp") simply falling through those tiny holes, into the abyss below the level.
We patched the holes we found, tweaking the geometry until Damp no longer fell through. But then the game went into test at the publisher, and suddenly a flood of "falling off the world" bugs were delivered to us. Every day a fresh batch of locations were found with these little holes that Damp could slip through. We would fix that bit of geometry, then the next day they would send us ten more. This went on for several days. The publisher's test department employed one guy whose only job was to jump around the world for ten hours a day, looking for places he could fall through.
The problem here was that the geometry was bad. It was not tight and seamless geometry. It worked on the PC, but not on the PS1, where the fixed point math vastly magnified the problems. The ideal solution was to fix the geometry to make it seamless.
However, this was a vast task, impossible to do in the time available with our limited resources, so we were relying on the test department to find the problem areas for us.
There's never time to do it right, but there's always time to do it over. If this sounds familiar, you're not alone. I have at times found myself slipping into this pattern, continually patching the same code over and over. It's the kind of code that, when submitted for code review, you're tempted to self-deprecatingly introduce as have you met my dog, patches?
While "patchiness" isn't always a bad thing -- the venerable Apache HTTP Server is testament to that -- it's probably an exception.
the original FAQ on the Apache Server project's website, from 1996 to 2001, claimed that "The result after combining [the NCSA httpd patches] was a patchy server."
Reading the Gamasutra article shamed me into to attacking a section of extra-patchy Stack Overflow code. Code which I constantly had to tweak in various ongoing ways to get it to work right. But first, I had to get over my fear. Fear. That's what led to all the patching in the first place. It was obvious this was working code which had become crufty over time, but it was working. And it's one of the core bits of functionality in the site. In those circumstances, it's easy to mentally justify "just this small change, just this once" rather than the fundamental rewrite you really need.
When you finally realize you've spent the last six months telling yourself the same "just this small change, just this once" lie, then you've met your dog patches, too.
Now what are you going to do about that rascally scamp?
My nieghbor had a gopher problem. Filling in each hole that appeared never really fixed his yard. Based on his experience I've decided to remodel my kitchen.
Steve Steiner on August 28, 2009 2:05 AM'Total rewrite' is usually based on the logic:
1. I have a bug I cannot fix. This is making me look bad.
2. powerpoint slides, design documents and prototypes do not have such bugs.
3. So if I am doing them instead of debugging, I will not look bad.
Projects generally only fail for technical reasons at the point of delivery. So if delivery is pushed off, technical failure becomes impossible. Chances are, some random non-technical issue will intervene to scrap the project before delivery of the new version. Or else you'll be in a different job, with +3 years experience of whatever cutting-edge technology was picked for the rewrite.
That's completely different from taking the worst 5% of the code-base out and shooting it like a mangy dog. People who do complete rewrites do so because _they don't know which dog to shoot_.
soru on August 28, 2009 3:16 AMHad the same problem with some awful interface code that imported csv files into Siebel via escript. Every change we made to the system even if its had nothing to do with the area it was importing to resulted in 3 days of retweaking this godawful code.
It could have been rewritten in about a month (it was a stinker in terms of structure, and using csv is fraught at the best of times when you have users with excel in different setups all over the place), but it was "90%" there to begin with ( I REALLY REALLY should have said no, redo it before we put it live, but was sort of persuaded to go with it). I think the real problem was the HPC said initially it wa 3 days work - probably the biggest lie I've ever heard in a meeting.
anyway 6 months later I'm still there fixing this utter utter hell of an interface without being able to rebuild it (even then it would have only been a "bit" better, the entire design was flaky because it was from a previous system which handled errors by ignoring them.
I'm with Craig - give yourself the safety net of a set of unit-tests which you develop to confirm the current operation and fail on the areas you know need to be reworked. Then change-away :)
Nij on August 28, 2009 3:39 AMThought I'd better add the pressure was always on to get it working and running again until the next bug. It was always a case of 'next time' to fix the glaring problems (one of which was it it the 16 k code limit before it was working - there was some real hacking to get to 90% therebefore we started.
This was for 1 country - we then were forced to do the same for another 10 in short order so a copy was done with some more hacks and stupidity we got that sort of working.
Eventually we moved everything over to something that did work , but it was 18 months of hell as far as I'm concerned.
thankfully we have a bit more clout that we can push back and say 'no, this is stupid' a bit more but the point i'm essentially making is that despite everything its not always your choice in how these things end up.
Corrigendum ad infinitum
Jakov on August 28, 2009 4:15 AMNow this is something I can agree with :)
workmad3 on August 28, 2009 5:10 AMFunny thing you write this now, 'cos I'm busy doing just that - patching my heavily patched code and avoiding a rewrite! And look, I finally get to make the first comment on a proper blog post. Yay. Time to go now, that patch isn't going to write itself. ;-)
Milo on August 28, 2009 5:11 AMDon't let yourself get attached to anything you are not willing to walk out on in 30 seconds flat if you feel the heat around the corner - Heat (1995)
(http://javadots.blogspot.com/2009/08/software-design-comes-to-hollywood.html)
Itay Maman on August 28, 2009 5:24 AMReminds me of the old adage: Where do you most fear the bug is? That's probably where it is.
John on August 28, 2009 5:25 AMCounterexample: Evolution. Nothing but patches. Ever.
Now that's one cute dog.
Jef Claes on August 28, 2009 5:53 AMreminds me of this Eric Lippert's post:
http://blogs.msdn.com/ericlippert/archive/2009/06/01/bug-psychology.aspx
cute dog
Andrei Rinea on August 28, 2009 6:00 AMI found myself continuously fixing the same code over and over again simply because I am not smart/skilled enough to rewrite it in a better way. A way that wouldn't require any fixes at all. But doesn't this seem as an impossible chimera, at least in the common case? I think that one should have really extensive experience as a coder so that he can afford to throw away a half-working code and start over again. The chances, at least for the average programmer, are that he would produce the same half-working code but with different look.
Genady on August 28, 2009 6:05 AMI think you chose a picture that is too cute to represent this problem.
I had a hard time feeling the analogy, given the cuteness of the dog.
But that is the problem, its tempting to just ball of mud it up. When I have been a consultant, it has been my main task to convince the lifers that this is their MO. And that while it works in the short term, they are lifers and they'll be the ones dealing with it in a year when they have no clue why it got so bad.
Good post, concise.
developingchris on August 28, 2009 6:07 AMIronic that you've regularly poo-pooed the value of unit testing. One of the most valuable aspects of testing is giving you more peace of mind that you can change code without breaking things.
Maybe if you had tests, you wouldn't be so hesitant to fix your code.
Patrick on August 28, 2009 6:15 AMI *deeply* feel this pain. It's what caused me to write this yesterday:
Will the defendant please rise. After having your code reviewed by a jury of your predecessors, you have been found guilty. I sentence you to life in prison with no possibility of parole. May God have mercy on your soul.
Corey Furman on August 28, 2009 6:15 AMI don't fear meeting my Dog as much as taking over someone else's Dog.
Mine might just growl at me, but the other Dog most properly will bite me especially if the owner has already left the company.
Also, if you a fellow programmer tells you a complex piece of code (preferably part of the core) is working, don't touch or change it. There is a good chance you'll find a Dog in it.
And I am talking out of experience.
Schalk on August 28, 2009 6:22 AMWe've been finding that "it's working code; what'll happen if we change it is" means we have insufficient regression testing. Rewrite the darn thing and throw your automated test suite at it. In the morning, you'll know your change was good!
Chris on August 28, 2009 6:23 AMThis is the type of situation that test driven design/refactoring are supposed to fix. If (big if) you have tests for the interfaces, rewriting the implementation is risk-free, because you will know whether you caught everything.
As counterpoint, here's your mate Joel on why the worst thing you can ever do is 'do over.'
http://www.joelonsoftware.com/articles/fog0000000069.html
The "falling off the world" problem is easily fixed by making "Damp" fatter.
Captain Obvious on August 28, 2009 6:46 AMYeah, nice dog BTW ;)
Gr33n3gg on August 28, 2009 6:54 AMThis whole problem gets alot worse when you have a boss that sees full rewrites as a big waste of time and insists you just make small changes to get things working. Over time the system becomes worse and worse until it is totally unmanageable.
My way out has been to do refactors on the side while doing my main work so when the time comes I can merge in my clean rewrite without needing to tell my boss I'll need a few days to redo things.
Toby on August 28, 2009 7:02 AMWhat you describe is the way how my company wants me to work... but I refuse to work that way. If you write a piece of code and you cannot get it the right first time, that is okay. Rarely you can really get it the right first time. There is a problem? Fix it. The fix doesn't always work, fix the fix. The fixed fix is too aggressive? Make some exceptional rules. However, if you then see it's still not working right and every new fix just gets me feedback that now this or that is broken - throw this piece of crap away.
Maybe you cannot ever get it perfectly right because the code was the utterly wrong approach from the very beginning. Rewrite from scratch has solved so many issues already. My supervisors always get mad at me when I do that... but once rewritten, the code works, no more patches, everyone's happy. So they calm down and maybe 6 months later they say "Remember how mad we have been that you rewrote all this code without our permission? I think it was the right thing to do". Of course it was!
It's just unbelievable how masochistic some programmers can be and keep on patching and patching and patching. My threshold for pain is somewhat lower regarding this aspect. No rewrite has ever caused worse code than we already had - either it got better... it I rewrote it three months later again :-P
Mecki on August 28, 2009 7:06 AMCount me in! I've been patching some code for a week now. Opened the reader this morning and found this post. :)
Jorge on August 28, 2009 7:13 AMThis is what I call stochastic debugging. You know it is fundamentally broken, but you hope you're going to find all the places where a user can tell. Even if you've found them all, you'll never know you're done; there could be one more. And it is *still* fundamentally broken.
Ole Eichhorn on August 28, 2009 7:16 AMSo what was the "extra-patchy Stack Overflow" you attacked? How long did the rewrite take? Was it successful? Have you had to add any new patches? How does the new code compare to the old? Where there any specific reasons you'd had so many problems in the first place?
I look forward to reading part 2.
Phenwoods on August 28, 2009 7:22 AMIt seems a little Schnauzer, like my sister's.
lluis on August 28, 2009 7:33 AMYay! Good post. I'm actually doing that right now with the website I'm working on by rebuilding the basic framework from the ground up. (It should still work with the actual pages in much the same way, so it's not a terribly gruesome task.) Totally in touch with the emotion, some of the code I'm referencing for the build would make a coder blush, and I think I even wrote some of it... -_-
It's always amazing to me how bad some of my own code looks 2 years after I wrote it. But then again, 2 years ago I barely knew the language. ^_^
PS-- Captcha: "hall brains"
Nicholas on August 28, 2009 7:36 AMBeen there, done that, decided an Electrical engineer has no business pretending to be a software engineer in the first place.
Allen on August 28, 2009 7:37 AM@Dylan:
Joel's post made a lot of sense when he wrote it in 2000, but that Netscape rewrite gave us the Gecko rendering engine and ultimately Firefox.
Maybe it wasn't such a bad idea after all...
Aidan on August 28, 2009 7:59 AMThe quoted example is a case of bad design. The collision system should've been designed to first of all share vertices among triangles and second to map out accessible space, not inaccessible solid.
Core Xii on August 28, 2009 8:05 AMReplace PS1 with something that works. :)
captcha: $3.4-billion mordants
securityhorror on August 28, 2009 8:10 AMI shall ask the stakeholders what they want to do with the rascal.
Francesco Rizzi on August 28, 2009 8:26 AMI couldn't agree more with you Jeff. ESPECIALLY in the games industry we rely far more heavily on large QA departments than we do on unit testing or any other proactive solution.
The common game development process is extremely iterative with your design being developed with your engine. Developing proactive testing solutions for your code is often not worth it if the code will change next month. It also boils down to the fact that QA departments can be shared amongst several studios such that there is no down-time for them and they are getting paid hourly wages that are close to minimal wage (or less if outsourced to another country). In many cases, it's just simply cheaper to have a large QA department bang out for weeks on end the most obvious and obtrusive bugs and let some junior level programmer patch it while your mid level and senior level guys continue to grind away at implementing new features or change key design elements based on designer needs. This segways into some fundamental flaws in the development strategy of games but I'll spare you that rant.
Salec on August 28, 2009 8:46 AMI hope you took the time to wrap that section of code with unit tests before you went in and refactored. Double bonus -- you make sure it's still working as expected and next time you won't need to avoid making changes because you're afraid you'll break it.
pleaso jeep
tvanfosson on August 28, 2009 8:55 AMIt's so sad, but this is typically the way corporations work. developingchris, above, got it right. It's the standard MO of IT programmers. I have tried to change this, but when new functionality requests come in, most of the team does the same as they always do: just keep cobbling on to the existing foundation. Depressing though it seems, this is unlikely to change in most shops.
Bernard Dy on August 28, 2009 9:01 AMI agree with earlier commenters that your real problem might be that you need to write (more) tests for that (specific part of the) code. If you have a fast-running test suite it should be pretty easy to see that on ctrl+s you just broke your tests, hit ctrl+z a few times and try again. Or do you have plenty tests and is the problem that you cannot get your test suite to pass in any other way than the current patch code? If so, perhaps your current test suite tests too specifically, that is, it tests only that your code is written as it is now, rather than testing how the code should behave?
Sverre Rabbelier on August 28, 2009 9:15 AMWill this dog do?
www.samugliestdog.com
Sam was crowned the world's ugliest dog three times.
TonyR on August 28, 2009 9:42 AM@Dylan
"If you are writing code experimentally, you may want to rip up the function you wrote last week when you think of a better algorithm. That's fine. You may want to refactor a class to make it easier to use. That's fine, too. But throwing away the whole program is a dangerous folly, and if Netscape actually had some adult supervision with software industry experience, they might not have shot themselves in the foot so badly."
From your linked article. Joel's article on "don't rewrite the netscape browser" isn't really a counterpoint.
BG on August 28, 2009 9:50 AMI had a refactoring win recently. There was one section of code that needed to be modified for a defect fix, but I could see that the whole method, a tangle of nested 'if' blocks, needed to be reorganized. Since there were no unit tests for the code, I created a test harness that covered the section 100% on existing behavior. Now, with a test harness safety net, I was able to fix the defect and simply the logic in the method, all while retaining the exact behavior that I started with.
Craig Boland on August 28, 2009 10:02 AMMy solution: hire a very skilled coder (temporarily), looking to it with a completely fresh eye. The fresh look combined with the skills should generally come up with a creative, longer lasting solution to the problem at hand.
More importantly: detect early on in the process that you are only patching the patchy dog. Only then it becomes sensible to pay an external coder to solve your patchy patch-dog code.
Ruudjah on August 28, 2009 10:03 AMthese random analogies are becoming quite ridiculous, no?
Pdm on August 28, 2009 11:07 AMI'm wondering what you think of the programming antihero at the end of the article. It sounds like a bit of too-much-cleverness.
Alex Vincent on August 28, 2009 11:21 AMI'm wondering what you think of the programming antihero at the end of the article. It sounds like a bit of too-much-cleverness.
Alex Vincent on August 28, 2009 11:22 AMAh patche.. i've been doing that since i started working in my actual job, why?, is not like I am not able to rewrite the code but the time they gave me to finish the correction is too short, so.. patch.. give me the power to complete my work.. and it (sadly) works!
dracov on August 28, 2009 11:40 AMYep, that's a Miniature Schnauzer without the cropped ears--like mine! Great dogs. Now, what was this post about...?
ChrisL on August 28, 2009 11:50 AMThere's a grammatical mistake towards the end "shamed me INTO TO attacking a section" should be "shamed me INTO attacking a section." Time for another patch!
Octoberdan on August 28, 2009 12:01 PMSomething like this happened to me recently as well. I had a particular piece of code, where my boss said "the last guy told me to tell you it's tricky to work with." /facepalm. 3 weeks of consistent bug reports day by day with this piece of code. It boggled my mind how convoluted this thing was. After those 3 weeks, I decided to 'screw it' and rewrite the thing from scratch. Took a couple of days to iron out the details but it's been going fine for a few months now.
Turns out that this piece of code had been patched and patched (ad infinitum) for about a year.
Steve-O on August 28, 2009 12:06 PMHave your test coverage, and you will feel much more safer doing bigger changes. Now, of course, the question is wider that just that, it's more about human psychology, and so far the answer is - patch until it is totally unbearable, and rewrite then. Long and painful way to go. Does anyone know better?
skoptelov on August 28, 2009 12:46 PMI am usually not afraid to rewrite/refactor my own code. Diving into someone else's mess - *that* I think twice about (or however many times it takes to convince myself to not do it).
The bigger, and older, someone else's mess is, the less inclined I am to fix it. Several gigs ago I worked on legacy code that was so poorly written and architected, that nobody on the team wanted to touch it any more than was necessary to patch it or add to it. Never mind the methods with 5000 lines of code, and/or 25 inner methods - the architecture (if you could call it that) just plain sucked. I called it the upside down pyramid architecture because if you didn't balance your patches/additions just right it would fall over and crash every time. Hell it would crash if you looked at it cross-eyed.
Everybody (except management/marketing/sales) wanted to start from scratch, and we started to several times, in small modules, but even that is hard when you are working on the holy cash cow for the company and the legacy code is not modular so you can't replace modules.
Of course, the hardest part of refactoring/re-writing anything is convincing the management to let you write something that to them is already finished (so what if it has a few bugs?).
Developer Dude on August 28, 2009 12:51 PMMy experience is that patch vs rewrite is an engineering tradeoff question, a risk management question.
Or, as everyone loves to hear, "It depends".
Paul Nathan on August 28, 2009 1:39 PMI agree completely with the original Gamasutra post, but I think the Coding Horror version is missing the point. In the Gamasutra piece, fixing the bug is the key point:
“That experience soured me against "the patch." Now I always try to dig right down to the root cause of a bug, even if a simple, and seemingly safe, patch is available.”
By contrast the Coding Horror version talks about a fundamental rewrite:
“In those circumstances, it's easy to mentally justify "just this small change, just this once" rather than the fundamental rewrite you really need.”
In my experience, fixing a bug by identifying its root cause is usually a better solution than rewriting from scratch. In fact, I often find that when the cause of a bug is really understood it can often be fixed with minimum code changes. Complete rewrites are sometimes an indication that the developer doesn’t know what the problem is, and may just end up back at square one.
I’m not saying this is the case with the Stack Overflow code, there isn’t enough information in this article to tell, but this post does seem to suggest that the only problem is that the code had become crufty. By all means clean up crufty code, but don’t confuse that with bug fixing.
Nice point !
Not only in development or maintenance this scenario happens in many aspects and areas of out lives.
You must read Hacker News...
Seth on August 29, 2009 9:00 AMI'm with Mahesh. This made me think of all the times I've seen people (of various professions) apply the same patching mentality in other areas of their lives: maintaining their vehicles, their finances, etc. Some of it may be the American culture of immediate gratification. It is so much quicker (in the short term) to just patch things!
Will on August 29, 2009 10:25 AMWhen I keep coming back to the same section of code, or having to fix the same problem in different sections of code again and again that is a flag to me that just screams refactor.
In fact, I like to hold off on gratuitous refactoring until I start seeing red flags like that going up. Then I take a look at the code and spend a couple of days making a new interface, testing the interface and implementing it in the code base.
I have done this before for newline conversion, with parent-child communication, and with string and buffer handling.
You will get a lot of push back from people saying that there is no time to do things right. "We are way too busy carrying buckets of water to unroll the fire hose." People like to look busy, they like to miss deadlines because it makes them look important. People that just calmly do the work on time never get any attention. But people who had to heroically battle a deadline despite having to patch the code in 1000 places in a 24/7 battle around the clock and get the code out just a week behind schedule look like heros.
Sad, but true.
Jimmy the Geek on August 29, 2009 11:47 AMhmm. sounds a bit,err, odd.
surely you write code to fix the geometry ? ie within a threshold weld vertices to near edges of adjacent polys, even if it involved basically retesselating the level, it'd still end up more friendly for the ps1 cache and vertex data was prolly texture data anyways.
It seems my job description should be Patch Developer. It annoys the hell out of me that my employer never allows the time to do something right and forces me to do something right NOW.
Robert Ferentz on August 30, 2009 3:48 AMAh, the 'complete rewrite' of the 'crappy legacy code' that just so happens to be the foundation of the company's main source of income.
Been there, done that twice - in two separate companies.
First one: lasted 12 months - started with 18 engineers working on the rewrite. 12 months later I was the only one left - everyone else had been pulled back to do maintenance on the legacy code. As each engineer got pulled from the rewrite project it's ETA sprinted further away into the future until it became obvious that it was never going to make it. To do certain rewrites you really need a company with a lot of spare cash that can afford to keep a maintenance team and a separate rewrite team going in parallel - sharing resources across both will never cut it.
Second one: lasted about 6 months - surprisingly not much actual code written as I spent most of the time in meetings while BAs, internal users and management argued about 'what to build' (hence no coding took place). The real problem there was one of the managers had a solution in his head from day one - outsourcing to a third party tool. When it became clear the tool option would cost around $500K there became an uneasy stalemate. I proposed a different approach: a piecemeal, module by module migration of the existing crap code to 'refactored good code' - a solution which would allow ROI with every iteration of the process but that was way to logical and the least expensive option so of course that was never going to fly =)
blinko on August 30, 2009 6:12 AMActually the *real* problem in the second case above was that the legacy stuff wasn't documented anywhere. Over many, many years hundreds of business rules had been implemented in the code but never documented anywhere. To rewrite it from scratch presented enormous risk - how would you know if you've implemented all the subtle, undocumented business rules in the new code?
and of course this project suffered from the 'flavor of the month' language syndrome and so its different modules were written in C, Java, shell script, Python, Visual Basic (used to write a very dodgy windows app) and some parts even suffered the misfortune of being written in some now unsupported 3GL... what a mess!
Counterexample: Evolution. Nothing but patches. Ever.
SteveC
True, but one hell of a lot of testing, continuous integration/rejection, no broken builds by definition, production system core unaffected by huge deviations from statistical mean, no apparent target output either.
countercounterpoint on August 30, 2009 7:52 AMCounterexample: Evolution. Nothing but patches. Ever.
SteveC
True, but one hell of a lot of testing, continuous integration/rejection, no broken builds by definition, production system core unaffected by huge deviations from statistical mean, no apparent target output either.
countercounterpoint on August 30, 2009 7:52 AMFear Of Changing Code
http://hamagudi.com/2009/08/16/fear-of-changing-code/
We all know what happens to women who wear the famed red lacquered sole shoes. They are instantly filled with a wicked sense of sexy self and fall hopelessly in love with its creator: the great shoe designer Christian Louboutin. Christian Louboutin’s fascination for women’s footwear began as a child growing up in Paris, where he discovered the world of high fashion and glamour in the city’s nightlife. His early passion for dancing and showgirls inspired him to incorporate elements of costume into everyday designs. This whimsical and seductive union makes for utterly unmistakable and irreplaceable designs. He passed through the iconic fashion houses of Charles Jourdan and Roger Vivier before opening his flagship boutique in Paris in 1992, marking the birth of the Christian Louboutin brand. His be-jewelled heels have become the most coveted accessory on high-profile glamour girls all over the world. "Shoes are more than just an accessory; they are an extension of a woman.
http://www.christianlouboutins.de
http://www.christianlouboutins.de/christian-louboutin-pumps-c-12.html
http://www.christianlouboutins.de/christian-louboutin-sandals-c-13.html
http://www.christianlouboutins.de/christian-louboutin-boots-c-14.html
There's something to say about crappy programmers, but there's something else to say about crappy programming languages.
blabla on August 30, 2009 12:01 PMClassic examples of am amateur approach to software; dive in head-first into unknown shallow waters.
Sam on August 31, 2009 3:23 AMClassic examples of am amateur approach to software; dive in head-first into unknown shallow waters.
Anonymous on August 31, 2009 3:24 AMAs programmers we always want to work in a greenfield environment - writing completely new code, a chance to 'do it right'... but as most programmers are typically optimists they completely underestimate the time it will take to get a system that has the same feature set and caters for all the forgotten 'knarky' use cases that the current legacy code handles.
So unless you work for a Microsoft or Google with deep pockets then the funding for a complete rewrite will typically evaporate before you're 75% through the rewrite project.
blinko on August 31, 2009 4:04 AMIsn't this the exact problem that we're paid to solve? Don't all programming problems basically fall under this umbrella? Aside from the most trivial bugs, every bug puts you in the "rewrite or patch" dilemma.
There really aren't any hard or fast rules. Sometimes you have to go total rewrite, sometimes you gotta patch, but in the end, its having the experience, intelligence and sometimes intestinal fortitude to make that decision that separates the mediocre programmers from the great ones.
As an aside, I have a new spy name thanks to recaptcha. I will now be called Kartch Brosnan.
JB on August 31, 2009 7:42 AMThe patch is quite cute. I think I am going to feed him and rub his belly.
Practicality on August 31, 2009 10:33 AMI’m not saying this is the case with the Stack Overflow code, there isn’t enough information in this article to tell, but this post does seem to suggest that the only problem is that the code had become crufty.
supra shoes on August 31, 2009 1:29 PMI proposed a different approach: a piecemeal, module by module migration of the existing crap code to 'refactored good code' - a solution which would allow ROI with every iteration of the process but that was way to logical and the least expensive option so of course that was never going to fly.
jordan 6 rings on August 31, 2009 1:31 PMAs expected the Test-Driven-Flagellates all come moaning out of the wood-work. And I tend to agree 100% with them - in the places where the theories ACTUALLY apply. Have you ever inherited a web application where the CSS has looked and acted like a house of cards? Just one small change to the style of the left menu? Please sir, can I have some more [time, much, much more time]? Ho hum, no manner of automated testing will fix this. Oh .. but that's just the domain of those scum eating web-developers and front-end monkeys ain't it. If you have the chance, always rewrite the bastard.
Aidan de Graaf on September 1, 2009 5:36 AMHaving recently worked on a project that could be described as a major rewrite of some code that had hundreds of unit tests, and where my testing strategy was "get all unit tests working, and then try a few million logged production examples," I'd have to describe the belief that all you need to do is make sure the unit tests work as charmingly naive. Sure, your unit tests may have made sure that features A, B, and C all work independently. But did they cover the case where you had zero instances of feature A, three or more instances of feature B, and at least one instance of feature C (to cite the triggering condition for one of the production example behavior differences I found)? That's expecting a lot from a unit test suite.
My first run of the production cases, after achieving "all unit tests pass," turned up around 10% behavior difference/failures. The production cases were just a lot more complex than most of the existing unit tests. So yea for unit tests, but don't think that is sufficient when trying to replicate complex code.
That dog is cute...my dog patches is one hell of an ugly mongrel.
pudds on September 1, 2009 1:24 PMI agree, the dog is cute. Looks one I had a when I was younger. Kudos on your blog post.
Tom on September 1, 2009 1:41 PMAs with anything else, it's a tradeoff. There are times when it makes sense to patch, times when it makes sense to rewrite, and times when it's not clear. Are you going to do a rewrite for some minor "oops" bug that you could patch in 5 minutes? Obviously not -- that's a clear "patch" case. Are you going to patch when you are told to make your native app run on the web instead? Obviously not -- that's a clear "rewrite" case.
More generally, if the time to implement your current stack of changes without a rewrite is greater than the time to do a rewrite+current changes, then obviously you should rewrite. If you don't have any ideas for architectural changes, but just have a local change that needs to be made, then obviously, you should patch. In between is a continuum of cases where you (or your manager) needs to make an educated decision based on level of effort, a guess on future requirements, and business constraints. If a patch will take a day and a rewrite will take two weeks, will the *future* labor saved by the rewrite justify a rewrite, and if yes, will the customer tolerate the delay and labor charge caused by the rewrite? If the answer to either above question is "no", it's patch time. This is certainly not a trivial decision.
Morty A on September 2, 2009 2:14 AMIf a patch will take a day and a rewrite will take two weeks, will the *future* labor saved by the rewrite justify a rewrite, and if yes, will the customer tolerate the delay and labor charge caused by the rewrite?
Rev Bain on September 2, 2009 5:12 AMYes, I've met Patches, many times.
Though at the same time I've also rewritten many times. I usually decide to rewrite something when I can't stand the code anymore. I've just decided to rip out over a megabyte of code from a project where Patches ran free. I'd rewrite the entire thing but I really only need to rewrite the key essential parts. The part that works, works, the part I ripped out worked, but it was becoming a nightmare to maintain.
Alexander Morou on September 3, 2009 12:19 PMHi Jeff, great website. I can get stuck in here for hours reading your archives. I continually find it amazing, that even a noob programmer such as myself can relate to most the frustrations and idiosyncrasies mentioned in your posts.
Code is too satisfying and addictive to talk about. Keep up the good work.
Daniel Carvalho on September 8, 2009 12:55 PMby the way this blog became crap
posts are quite rare and not interesting as before
That is just the cutest dog on the face of the earth!
Cortaflex on September 12, 2009 4:14 AMThis has happened with most of us who try to make sense out of a project which has deadlines,limited resources and the responsibility lies on "you" to make it work !
The cute dog makes the article a bit lovable though :)
Why is it taking so long? I don't get it?
Bill on October 13, 2009 8:58 AMThanks for your information, i have read it, very good!
ed hardy shirts on October 23, 2009 8:09 AMYes I can merge in my clean rewrite without needing to tell my boss I'll need a few days to redo things.
casus telefon on November 13, 2009 1:06 AMI was just reading Joe Celko's article Getting Rid of SQL Code
http://www.simple-talk.com/sql/t-sql-programming/getting-rid-of-sql-code/
First mindset problem:
Once you have started in one direction, you stick to it. But the Turkish proverb is right: “No matter how far you have travelled down the wrong road, turn around”.
Brandon on February 6, 2010 11:22 PMI keep wisiting you blog and reading your archives for hours. I continually find it amazing, that even a noob programmer such as myself can relate to most the frustrations and idiosyncrasies mentioned in your posts.
telefon dinleme on February 6, 2010 11:22 PMThe comments to this entry are closed.
|
|
Traffic Stats |