working with
legacy code
Mark Jones
NewVoiceMedia
what is legacy code?
Legacy code is code not under test - Michael Feathers
Legacy code is code you're afraid to change - Mark Seemann
Code where the intention isn't clear, and hasn't had any love - Anon
Code nobody wants to work on - Anon
Legacy code is code that makes you laugh and/or cry - Mark Jones
Examples of legacy code
hard-baked dependencies
old technology
intention is unclear
What causes legacy code?
No ongoing design
No tdd
Consequences of untested code
When you change the code, you can't guarantee you won't break it
The code can't be refactored
Refactoring: "disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior" - Wikipedia
changes will be harder
bug count will increase
MORE manual testing
The code is expensive
why would code have no tests?
developer optimism
technical constraints
TIME CONSTRAINTS
How do you prevent Legacy code?
best practices
TDD
refactor to patterns
keep code clean
Pair program
Peer code reviews
adding tests to legacy code
run the code as far as you can
break dependencies
smallest changes POSSIBLE
sensing variables
prove test is correct
by changing code
coverage before refactoring
refactor
extract interface
[code]
sensing variable
[code]
wrap static
[code]
replace static method with lambda
[code]
dealing with singletons
[code]
adapt parameter
[code]
Me: | Mark Jones |
Employer: |
NewVoiceMedia |
Twitter: |
@m_j_o_n_e_s |
Blog: |
possiblythemostboringblogever.blogspot.co.uk |
Legacy code
By Mark Jones
Legacy code
- 1,342