Over its lifetime, software often falls into a vicious circle: Enhancements make the code more difficult to understand, increasing the likelihood of errorsincluding errors in the changes meant to repair the previous generation of bugs. Continue unti
Over its lifetime, software often falls into a vicious circle: Enhancements make the code more difficult to understand, increasing the likelihood of errorsincluding errors in the changes meant to repair the previous generation of bugs. Continue until collapse.
Containing this software entropy is the mission of re-factoring, the practice of continually seeking out redundancy, identifying poorly located data or functionality, and transforming code in ways that do not change its function but increase its understandability.
"Re-factor mercilessly," commands consultant Ron Jeffries, editor of an extreme programming Web site (www.xprogramming.com). "When you find two methods that look the same, you re-factor the code to combine them. When you find two objects with common functionality, you re-factor to make there be just one."
Considered apart from other practices, re-factoring could sound like a cure that perpetuates the disease. It might seem that re-factoring tries to mitigate the risks of necessary change by looking for ways to make merely cosmetic changes. Like the diet without exercise, re-factoring alone will produce disappointing or even counterproductive results.
Re-factoring must be combined with other extreme programming practices that include continuous testing and integration (nothing that breaks the code ever gets beyond the daily build) and simple design (never deploying code that does more than is needed today).
Extreme programming doesnt try to forestall software change by anticipating future needs; rather, it treats changing needs as a certainty and tries to reduce software update costs by mandating reliable processes.
Developers will do well to perform their re-factoring with the aid of high-level tools, such as Rational Software Corp.s Rational XDE and TogetherSoft Corp.s ControlCenter, and supportive programming environments. Smalltalk programmers, for example, take for granted the ability to find all senders of any given method, easing the task of redirecting those messages to a new method that re-factors one or more others.
But re-factoring tools cant completely automate a simple mechanical process. There are similarities that are inherent and candidates for re-factoring, but there are other cases where consolidation might impede refinement of separate features.
Nor can re-factoring repair an organizational problem. If a company has a dozen Web sites, there are probably corresponding divisions among the business units. Those will have to be addressed before re-factoring can do its job.
Technology Editor Peter Coffee can be contacted at email@example.com.