Refactoring
Recently I brought this book, and found it pretty interesting. I will share some summary here, to get you thinking :-)
What is Refactoring
"Improving the design after it has been written." It is a change, made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior. It is basically cleaning up code, but in an efficient and controlled manner, that results other code changes (like new functionality or performance improvement) much easier.
Without refactoring the design of program will decay. The harder is to see the design the harder is preserve it. Refactoring made software easier to understand.
Refactoring help to find bugs. With code refining, bugs that was hidden in not understandable design, will be visible.
Refactoring helps to program faster. It is a little overhead at the beginning, but later new changes will be easier and easier to add, because of the code is more flexible and clean.
Refactoring should take place normally during the development process, with little steps. You don't code because your refactor, you refactor because you want to do something else, and refactoring helps you do that thing.
Three strikes and you refactor If you third time do the same, you must refactor.
When you need to add a functionality, and code is hard to get, you refactor first, and add the functionality.
You should refactor to easier to spot a bug.
Refactor as you do a code review (suggestions made by the team).
Refactoring is alternative of upfront design. This way, you don't do too much (or at all) upfront design. You just code your first approach, and get it working, after you refactor it in any shape. The essence of refactoring is the change. You don't find the ultimate solution, just a reasonable one. During work you realize a new design that fit better for the solution, and just refactor into it.
Refactoring can cost performance, but later it win on a long run. As code easier to understand and well designed, profilers spot hard points easier, and you get faster for performance solution, than without refactor. So refactor first, then code for performance, and always with a profiler.
Bad smells in code
Coming soon...
