|
|
|
Sponsored Link •
|
|
Advertisement
|
Bill Venners: In Refactoring, you list several problems with refactoring, including situations when you shouldn't refactor. How do you decide when you should start from scratch and throw away existing code versus refactor it?
Martin Fowler: The answer is: I don't really know. If you have no tests and cruddy code, then you should probably throw it away and start again because you'll have to do all the testing, as opposed to if you have cruddy code with many tests. If the code is riddled with bugs, then behavior-preserving transformations will of course preserve the bugs, so that might be an argument against refactoring. I think the answer to your question also changes as your comfort level with refactoring increases. As you become more confident with refactoring, you'll want to refactor something that you'd otherwise want to rewrite because you're more skilled at refactoring.
Bill Venners: I was once in a situation where I was one of two consultants whose job it was to get a problem app working. I decided to throw away the piece I was responsible for and start over. The other consultant attempted to refactor, but ultimately his piece never became stable. Eventually I took that piece over, threw it away, and rewrote it from scratch. It seems like at some point, if the code just has no structure, it's more effective to rewrite it than refactor it.
Martin Fowler: It might not be a bad idea to spend some time
refactoring it to see how much progress you can make before deciding to rewrite it from
scratch.
Have an opinion about refactoring, unit testing, design, or extreme programming? Discuss this article in the News & Ideas Forum topic,
Refactoring with Martin Fowler
Resources
Refactoring: Improving the Design of Existing Code, by Martin Fowler with Kent Beck, John Brant, William Opdyke,
and Don Roberts is at Amazon.com at:
http://www.amazon.com/exec/obidos/ASIN/0201485672/
A catalog of summaries of refactorings mentioned in the book, Refactoring:
http://www.refactoring.com/catalog/index.html
A refactoring portal maintained by Martin Fowler contains links to refactoring tools and other refactoring sites:
http://www.refactoring.com/
Martin Fowler's links to extreme programming resources:
http://martinfowler.com/links.html
Articles written by Martin Fowler about XP and agile methods:
http://martinfowler.com/articles.html#agile
Patterns of Enterprise Application Architecture, by Martin Fowler is at Amazon.com at:
http://www.amazon.com/exec/obidos/ASIN/0321127420/
UML Distilled: A Brief Guide to the Standard Object Modeling Language, by Martin Fowler and Kendall Scott
is at Amazon.com at:
http://www.amazon.com/exec/obidos/ASIN/020165783X/
Planning Extreme Programming, by Kent Beck and Martin Fowler is at Amazon.com at:
http://www.amazon.com/exec/obidos/ASIN/0201710919/
Analysis Patterns: Reusable Object Models , by Martin Fowler is at Amazon.com at:
http://www.amazon.com/exec/obidos/ASIN/0201895420/
Martin Fowler's website contains many articles, book chapters, and other information from Martin:
http://www.martinfowler.com/
|
Sponsored Links
|