to make the software easier to understand and modify.引自 Chapter 2 Principles in Refactoring
A good contrast is performance optimization.重构可能使软件速度变慢,但是如果软件是良好重构过的,最后优化性能阶段能够带来良好结果,反而使软件性能良好
2.
refactoring does not change the observable behavior of the software
Why Should You Refactor?
Refactoring Improves the Design of Software
Refactoring Makes Software Easier to Understand
Refactoring Helps You Find Bugs
Refactoring Helps You Program Faster
即使在开发过程中,当你发现重复或相似的代码时,也应该立刻重构;当变化发生时,如果该变化影响不止一处,重构就应该粉墨登场。经常的重构可以保证代码常拭常新,如利刃一般锋利。“不要容忍破窗户”
如果两个或更多的地方实现同一职责,则改变时会带来麻烦。所以要遵循DRY原则,单一职责。
When Should You Refactor?
The Rule of Three(Three strikes and you refactor)
Refactor When You Add Function
Refactor When You Need to Fix a Bug
Refactor As You Do a Code Review
The most common time to refactor is when I want to add a new feature to some software.
Reasons:1.refactoring helps me understand some code I need to modify.2.another driver of refactoring is a design that does not help me add a feature easily.
What is it that makes programs hard to work with?Four things I can think of as I am typing this are as follows:
1.Programs that are hard to read
2.Programs that have duplicated logic
3.Programs that require additional behavior that requires you to change running code
4.Programs with complex conditional logic 引自 Chapter 2 Principles in Refactoring