70 likes | 308 Views
Refactoring. What is Refactoring? Martin Fowler’s Definition. 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
E N D
What is Refactoring? Martin Fowler’s Definition • 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 • When you refactoryou are improving the design of the code after it has been written
What sorts of actions occur during refactoring? • Break functions into smaller subfunctions. • Re-design class and class hierarchies • Rename variables and functions • Remove common cut/pasted code
Why Refactor? • If it works, don’t fix it. Right? • Any fool can write code that a computer can understand. Good programmers write code that humans can understand. -Martin Fowler • Code “Rots” • Original design does not anticipate needed modifications • What seems like a good design at first, proves not to be during implementation.
Why Refactor? (continued) • Refactoring improves the design of software • Refactoring makes software easier to understand • Refactoring helps you find bugs • Refactoring helps you program faster
When do you refactor? • Refactor when you add function • Refactor when you need to fix a bug • Refactor when you do a code review