Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up
for free
Confident refactors
Mehdi Lahmam B.
June 19, 2017
Technology
1
35
Confident refactors
Mehdi Lahmam B.
June 19, 2017
Tweet
Share
More Decks by Mehdi Lahmam B.
See All by Mehdi Lahmam B.
mehlah
0
370
mehlah
1
130
mehlah
0
9
mehlah
0
110
mehlah
2
730
mehlah
0
110
mehlah
1
260
mehlah
1
350
mehlah
0
49
Other Decks in Technology
See All in Technology
clustervr
0
170
muras
0
120
ytaka23
5
1.7k
recruitengineers
0
140
becolomochi
0
170
apcom
1
450
fu3ak1
0
980
noir_neo
0
130
pohjus
1
2.1k
hirosys
0
150
nkjzm
1
870
hgsgtk
4
1.2k
Featured
See All Featured
jakevdp
775
200k
scottboms
251
11k
hannesfritz
27
930
tmm1
61
8.5k
afnizarnur
176
14k
searls
204
35k
smashingmag
229
18k
jcasabona
7
520
myddelton
109
11k
paulrobertlloyd
71
3.6k
erikaheidi
13
4.2k
zakiwarfel
88
3.3k
Transcript
Confident Refactors
Mehdi Lahmam @mehlah
25kV Rails app, started in Feb 2009 Never rewritten 23k+
commits from 52 contributors
Ruby is a massively successful language!
Early success Making it easy to make new things
Later success Making it easy to maintain old things
Today, let’s refactor some legacy code
Today, let’s refactor some legacy code
Refactor - verb To change the design of code without
changing its observable behavior.
Refactor - verb To change in advance of a new
feature or bug fix, making the job easier.
Today, let’s refactor some legacy code
Legacy - noun Old code.
Legacy - noun Code without tests.
Legacy - noun Code that we don’t like.
Legacy - noun Code we don’t understand well enough to
change confidently.
Today, let’s refactor some legacy code
Refactoring is hard
Refactoring legacy code is very hard
Easy to accidentally break functionality
Legacy refactors feels unsafe
Legacy refactors are hard to sell
Business priority Cost / risks
Business priority Cost / risks New features
Business priority Cost / risks New features Bugs fixes
Business priority Cost / risks New features Bugs fixes Testing
Business priority Cost / risks New features Bug fixes Testing
Refactoring
Business priority Cost / risks New features Bug fixes Testing
Refactoring no selling needed easy to sell can often sell very hard to sell
Selling refactoring is hard ⏲ ⛔
Business priority Cost / risks Refactoring
Too much pressure ⏳ ⚒
Refactors are scary
What techniques we have? PDD - Pray Driven Development Fowler’s
refactoring book Characterization testing A/B testing, experiments
Refactors as surgeries
Refactors as surgeries Requires careful planning Follow a clear process
Multiple observations Flexible tools Things can get bloody
1. Plan 2. Cut 3. Record 4. Validate 5. Refactor
6. Verify 7. Compare 8. Fallback 9. Delete Clear process
None
None
None
Cut
Record
Validate ✅
Refactor <Insert magic here />
Verify
Compare ⚖
Fallback
Delete ✂
We dit it
We dit it Time to celebrate hard