Friday, July 29, 2011

Can Refactoring Improve Design ?

Yes, it can but not always!

When can refactoring improve design? Refactoring can improve design when team members who do refactoring are not only just programmers who know only language constructs but also are designers who know design principles. Team members who perform refactoring need to be experienced programmers. That is not enough. They need to know design principles in order to improve design. Else, they will not be able to figure out if the structure and association of entities or classes need to be changed in order to improve the design of software systems. They will focus only on a single program or subset of classes while refactoring.

Refactoring cannot improve design when we put programmers through a crash course on refactoring. It is essential to train them on object oriented analysis and design. They need to learn all design principles as well as programming principles. If we take this approach, yes, refactoring can improve design.

There can be extreme cases of dealing with complex or legacy code. Refactoring of legacy code is a costly affair. This requires experienced designers who have the ability to discover the hidden design.

In his article ‘Discovering Hidden Design’, Michael Feathers has articulated this very well with an example. It is a good read for all software professionals.

6 comments:

Goutam said...

I observed that developers perform code clean up in name of refactoring, which is against "do things right at first time". Refactoring will make sense, if we are bringing change in system, environment etc or achieve optimization to rearrange your components around your technical architecture/structure. Another analogy - if you bring new sofa in your house you redesign other objects to optimize, utilize space etc and perform clean up in your bachelor accomodation when you feel guilty of living with filth

Raja Bavani said...

Goutam, Well said! Good to see your comments.

Veena Gudi said...

Refactoring is definitely an art form and requires skilled designers to lead the show. It is perhaps more tricky than designing itself, as there are several restrictions against which one will have to work. I had read a book Refactoring to Patterns by Martin Flower during my development days, it was truly inspiring. Must read for any one who attempts refactoring...

Raja Bavani said...

Veena, Absolutely! Refactoring requires skilled designers. Skilled designers need to coach team members on effective refactoring techniques. Else the culture and and hence the benefits of refactoring may get diluted. Martin's book is a good read.

Vats said...

When it comes to architecting systems of enterprise scale, there could be times where the entire DB has to be replaced or the app servers are to be replicated. In such situations, it would be radically difficult and time consuming to incorporate necessary changes on to the system without applying refactoring principles.

Raja Bavani said...

Shrivatsan,

Good response! Thanks!