10Refactoring

Monday December13 2010 · ‹Programming› · ‹Design› · 2728 Views
 

What is refactoring? Most people will tell you that refactoring is about changing a system without changing its semantics. What does this mean and how is it related to programming?

Whenever we change code, consistency requires that we need to perform similar changes in many places at the same time. When such changes occur often enough, we recognize a pattern. Changing many instances of the pattern simultaneously is a burden and a risk to the programmer, which is why we refactor.

We refactor in order to capture the pattern in a single location. So after refactoring, any change made to this pattern is done exactly once. Semantics are preserved because the instantiated patterns are the same. The instantiation itself though, has been postponed to the moment when the instances are actually needed.

The copies of the pattern are no longer in the source code, but they nevertheless exist. The pattern is instantiated every time the code involving the pattern is executed.

What we changed is the domain of the pattern. We have moved the pattern from the spatial domain of source code to the temporal domain of execution. We have taken a spatial pattern and transformed it into a temporal pattern.

Now we can see the parallels between refactoring and programming. We program because we want to automate what would be tedious repetitive mechanical work. The machine performs the repetitive part and leaves us users to make the input which varies. In the case of refactoring, the programmer is the user and the repetitive mechanical work is programming. Considering the programmer as a user of the system, refactoring is simply programming.


0 Comments · 0 Trackbacks · Permalink · Share this!

Be the first to comment
 

 
E-Mail  (for notification only)
 
Code*  ←