5.
Refactoring is a disciplined technique for
restructuring an existing body of code, altering its
internal structure without changing its external
behavior. Its heart is a series of small behavior
preserving transformations. Each transformation
(called a 'refactoring') does little, but a sequence
of transformations can produce a signiﬁcant
restructuring. Since each refactoring is small, it's
less likely to go wrong. The system is also kept
fully working after each small refactoring, reducing
the chances that a system can get seriously
broken during the restructuring.
(Martin Fowler - Refactoring.com)
The Power of
Refactoring

6.
Code refactoring is the process of
changing a computer program's code to
make it amenable to change, improve its
readability, or simplify its structure, while
preserving its existing functionality.
(wikipedia)
The Power of
Refactoring

7.
So basically...
• Improve small parts of the code for...
• Readability
• Performance improvement
• Implementation or change of logic
The Power of
Refactoring

8.
But watch out!
• It should not break existing functionality
• Remain a consistent API/interface
The Power of
Refactoring

12.
Why refactoring?
• Prototyping
• Quickly have a clickable interface
• No need for full functionality yet
• As long as structure is OK, refactoring
into ﬁnal product is easy
The Power of
Refactoring

13.
Why refactoring?
• Unclear specs
• Something needs to be implemented
• but you don’t know how!
• Create a basic API and call it
• Implement it later
The Power of
Refactoring

23.
Some requirements
• Unit/functional tests need to be in place
• API needs to remain exactly the same
• API needs to be good enough
• if not, then rewrite instead of refactor
The Power of
Refactoring

29.
Project A: Unclear
specs
• Halfway the project, client ﬁnally decides
• Easy to implement: just refactor the
authenticate method
• Rest of the code does not care, as long as
you keep the API the same
The Power of
Refactoring

32.
Documentation helps
• Good rule of thumb
• If you need to change
the method
documentation,
reconsider
The Power of
Refactoring

33.
Project B: Code
improvement
• You took over management of another
developer’s code
• You wrote some crappy code yourself
• Advancements in technology made better
things possible (much more likely! ;-)
The Power of
Refactoring