6. If the Code is Hard to Understand Hard to maintain Hard to improve Hard to work with evolutionary design More expensive
7. What is Refactoring? A series of small steps, each of which changes the program’s internal structure without changing its external behavior - Martin Fowler Verify no change in external behavior by Testing Using the right tool (IDE) Formal code analysis by tool Code review or pair programming Being very, very careful
8. Prerequisites for Success Safety net Everybody agreed “Collective code ownership” Common understanding of refactoring methods Supportive environment Powerful IDE
16. Main Goals Organizing data Composing methods Making methods calls simpler Moving features between objects Simplifying conditional expression Dealing with generalizations
18. When to Refactor? When add new functionality Refactor existing code until you understand it Refactor the design to make it simple to add When try to find bugs Refactor to understand the code During code reviews Immediate effect of code review Allows for higher level suggestions
19. Key Elementsof Refactoring Simplifying complex statements Abstracting common solutions into reusable code Removal of duplicate code
We need to realize that software must be soft: it has to be easy to change because it will change despite our misguided efforts otherwise.
• Make a small change (a single refactoring)• Run all the tests to ensure everything stillworks• If everything works, move on to the nextrefactoring• If not, fix the problem, or undo the change,so you still have a working system
Any time you find that you can improve the design of existing codeYou detect a code that smellsAfter static analysis
Any time you find that you can improve the design of existing codeYou detect a code that smellsAfter static analysis