When Should You Refactor
When Should You Refactor
1 of 6
https://sourcemaking.com/refactoring/when-should-you-refactor
Facebook 718
Twitter 1076
Google+
Refactoring (/refactoring
When I talk about refactoring, I'm often asked about how it should
be scheduled. Should we allocate two weeks every couple of
months to refactoring?
In almost all cases, I'm opposed to setting aside time for
refactoring. In my view refactoring is not an activity you set aside
time to do. Refactoring is something you do all the time in little
bursts. You don't decide to refactor, you refactor because you
want to do something else, and refactoring helps you do that other
thing.
Introduction to
Refactoring (/refactoring
/introductionto-refactoring)
Introduction to
Refactoring (/refactoring
/introductionto-refactoring)
Defining Refactoring
(/refactoring/definingrefactoring)
Here's a guideline Don Roberts gave me: The first time you do
something, you just do it. The second time you do something
similar, you wince at the duplication, but you do the duplicate thing
anyway. The third time you do something similar, you refactor.
10/12/2015 11:03 AM
2 of 6
https://sourcemaking.com/refactoring/when-should-you-refactor
Code smells
(/refactoring/bad-smellsin-code)
Duplicated Code
(/refactoring
/duplicated-code)
Long Method
(/refactoring/longmethod)
Large Class (/refactoring
/large-class)
Long Parameter List
(/refactoring/longparameter-list)
Divergent Change
(/refactoring/divergentchange)
Shotgun Surgery
(/refactoring/shotgunsurgery)
Feature Envy
(/refactoring
/feature-envy)
Data Clumps
(/refactoring/dataclumps)
Primitive Obsession
(/refactoring/primitiveobsession)
Switch Statements
(/refactoring/switchstatements)
Parallel Inheritance
Hierarchies (/refactoring
/parallel-inheritancehierarchies)
To make this process work, you have to have small review groups.
My experience suggests having one reviewer and the original
author work on the code together. The reviewer suggests
changes, and they both decide whether the changes can be easily
refactored in. If so, they make the changes.
Speculative Generality
(/refactoring/speculativegenerality)
Temporary Field
(/refactoring/temporaryfield)
Message Chains
(/refactoring/messagechains)
Middle Man (/refactoring
/middle-man)
Inappropriate Intimacy
(/refactoring
/inappropriate-intimacy)
10/12/2015 11:03 AM
3 of 6
https://sourcemaking.com/refactoring/when-should-you-refactor
Composing Methods
(/refactoring/composingmethods)
Moving Features
Between Objects
(/refactoring/movingfeatures-betweenobjects)
Organizing Data
(/refactoring
/organizing-data)
Organizing Data
(/refactoring
/organizing-data)
Self Encapsulate Field
(/refactoring/selfencapsulate-field)
Replace Data Value with
Object (/refactoring
/replace-data-valuewith-object)
Change Value to
Reference (/refactoring
/change-valueto-reference)
Change Reference to
Value (/refactoring
/change-referenceto-value)
Replace Array with
Object (/refactoring
/replace-arraywith-object)
Duplicate Observed
Data (/refactoring
/duplicateobserved-data)
Change Unidirectional
Association to
Bidirectional
(/refactoring/changeunidirectionalassociationto-bidirectional)
Reading is boring
Aren't you bored of reading so
much? Try out our new interactive
learning course on refactoring. It's
much more fun.
(/refactoring-course)
Change Bidirectional
Association to
Unidirectional
(/refactoring/changebidirectional-associationto-unidirectional)
Replace Magic Number
10/12/2015 11:03 AM
4 of 6
Refactoring
Helps You
Find Bugs
(/refactoring
/refactoringhelpsyou-find-bugs)
https://sourcemaking.com/refactoring/when-should-you-refactor
Introduction
to Refactoring
(/refactoring
/introductionto-refactoring)
What Do I Tell
My Manager?
(/refactoring
/what-do-i-tellmy-manager)
Simplifying Conditional
Expressions (/refactoring
/simplifying-conditionalexpressions)
Making Method Calls
Simpler (/refactoring
/making-method-callssimpler)
Making Method Calls
Simpler (/refactoring
/making-method-callssimpler)
Rename Method
(/refactoring/renamemethod)
Add Parameter
(/refactoring
/add-parameter)
Remove Parameter
(/refactoring/removeparameter)
Separate Query from
Modifier (/refactoring
/separate-queryfrom-modifier)
Parameterize Method
(/refactoring
/parameterize-method)
Replace Parameter with
Explicit Methods
(/refactoring/replaceparameter-with-explicitmethods)
Preserve Whole Object
(/refactoring/preservewhole-object)
Replace Parameter with
Method (/refactoring
/replace-parameterwith-method)
Introduce Parameter
Object (/refactoring
/introduce-parameterobject)
Remove Setting Method
(/refactoring/removesetting-method)
Hide Method
(/refactoring/hidemethod)
Replace Constructor
10/12/2015 11:03 AM
5 of 6
https://sourcemaking.com/refactoring/when-should-you-refactor
Dealing with
Generalization
(/refactoring/dealingwith-generalization)
Big Refactorings
(/refactoring
/big-refactorings)
Refactoring Course
new
(/refactoring-course)
My account (/user)
10/12/2015 11:03 AM
6 of 6
Refactoring (/refactoring)
UML (/uml)
https://sourcemaking.com/refactoring/when-should-you-refactor
Forum
(https://sourcemaking.userecho.com/)
Contact us
(https://sourcemaking.userecho.com
/?show_feedback_form_private=true)
About us (/about-us)
10/12/2015 11:03 AM