Refactoring: Improving the design of existing code

I have been hearing about this book for longer than I would like to admit.  After being in Information Technology for over fifteen years this book has been discussed numerous times.  I finally got around to reading this book.  Refactoring: Improving the Design of Existing Code by Martin Fowler discusses a lot of things many developers have been talking about for a long time.  This is probably partially because this book was published back in 1999.  Reading the book as it discusses Java 1.1 and Java 1.2 makes you realize it has been around along time.  Although this word is not know outside of the software industry it is used heavily inside the industry.

“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”

This how Martin Fowler describes Refactoring, these words are very important.  I have been guilty of violating the important premise of altering the external behavior.  Fowler and many of the other contributing authors detail the importance of having unit tests prior to making changes or Refactoring.

“Before you start refactoring, check that you have a solid suite of tests.  These tests must be self-checking.”

This is sage advice for all developers out there.  Without the solid suite of tests you are playing Russian Roulette with your code, I know this for a fact.

I found it interesting how naming variables and methods came up in this book as it did in Clean Code too.  Clarity is very important as we develop and modify our code.  There is always going to be someone new reading our code and the names must convey what in fact that code does.  In some ways these simple things like this make a huge difference.

Don Roberts’ Rule of Three: “the first time you do something, you just do it.  Second time you do something similar, you wince at the duplication, but you do the duplicate thing anyway.  The third time you do something similar, you refactor.”

The rule of three is analogous to the software development principle of DRY or Don’t Repeat Yourself.  When I look at old code I see this many times where I have copied a method and pasted it every where.  We need to have it in one spot only.  As we know this will change and we don’t want to change in ten different places.

Martin Fowler has a nice overview of Refactoring on his website.  It gives you a good visual representation of the creation of new code versus refactoring old code.

If you enjoy this please share and don’t forget to subscribe to our newsletter.

No comments yet.

Leave a Reply

Powered by WordPress. Designed by Woo Themes