23 August 2007

Refactoring

Refactoring
----------------

Refactoring is a Cornerstone in Extreme Programming.
But It is a Topic one should deal with it, regardless of his interest on XP.
I will introduce issue of refactoring with Martin Fowlers very precious intro.
After This I will go on telling about What Refactoring is by giving examples.




Refactoring is the process of changing a software system in such a way that it does not alter
the external behavior of the code yet improves its internal structure. It is a disciplined way to
clean up code that minimizes the chances of introducing bugs. In essence when you refactor
you are improving the design of the code after it has been written.
"Improving the design after it has been written." That's an odd turn of phrase. In our current
understanding of software development we believe that we design and then we code. A good
design comes first, and the coding comes second. Over time the code will be modified, and
the integrity of the system, its structure according to that design, gradually fades. The code
slowly sinks from engineering to hacking.
Refactoring is the opposite of this practice. With refactoring you can take a bad design, chaos
even, and rework it into well-designed code. Each step is simple, even simplistic. You move
a field from one class to another, pull some code out of a method to make into its own
method, and push some code up or down a hierarchy. Yet the cumulative effect of these
small changes can radically improve the design. It is the exact reverse of the normal notion
of software decay.
With refactoring you find the balance of work changes. You find that design, rather than
occurring all up front, occurs continuously during development. You learn from building the
system how to improve the design. The resulting interaction leads to a program with a design
that stays good as development continues.

No comments: