The document discusses refactoring code to improve its design without changing its external behavior. It defines refactoring as improving the code's internal structure to make it easier to understand and modify. The goals of refactoring are to remove duplication, simplify complex logic, clarify unclear code, and make the code easier to maintain without adding new functionality. It recommends refactoring when adding features, fixing bugs, or during code reviews. It also lists common "bad smells" in code and examples of refactoring techniques like extracting methods, moving methods, encapsulating fields, using interfaces, removing unused parameters, and replacing nested conditionals with guard clauses.
2. Refactoring Any fool can write code that a computer can understand. Good programmers write code that humans can understand. 2
3. Refactoring What is Refactoring? Martin Fowler : "a change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior“. William C. Wake : "Refactoring is the art of safely improving the design of existing code“. 3
4. Refactoring The process of refactoring involves the removal of duplication, the simplification of complex logic, and the clarification of unclear code. The goal of refactoring is NOT to add new functionality The goal is refactoring is to make code easier to maintain in the future 4
34. Refactoring Encapsulate Field you should never make your data public. When you make data public, other objects can change and access data values without the owning object's knowing about it. 12
37. Refactoring Replace Nested Conditional with Guard Clauses A method has conditional behavior that does not make clear the normal path of execution. Use guard clauses for all the special cases. Readability 15