Experiences with dealing with legacy code while delivering value. Key points: 1) Legacy code costs a lot. 2) Design must be maintained & evolved. 3) Continous refactoring during each task is a way to achieve 2.
3. by Jon Baldock nz @ flickr
We've all been there - mess of code
4. by Ignaz Wiradi @ wikimedia
What we would like to have
- clean, structured, fitting
5. by cotallo-nonocot @ flickr
What we do have. It (likely) started with st. small & clean but requirements evolved
while the design of the code did not - only hacked & patched
6. God class
● 15 kLOC
● 300 properties
● 320 methods
● 50 constants
● used everywhere
by mandalinarossa @ flickr
Example of legacy - a typical monstrous god class that we were confronted with.
8. True cost of legacy
Pain <= Time wasted in code archeology, money & time wasted due to bugs being
introduced.
Legacy code matters to business for real money are wasted there.
11. ?
How do we get from L to R? The sad answer is we don't.
It took centuries to build R. We can never get from L to R in a reasonable time. There
is too much mess, too much to fix.
12. Code Churn
Michael Feathers: Getting Empirical about Refactoring
Code-churn driven refactoring: improve where it matters & pays off most - complex &
changed often
13. => Boy Scout Refactoring
● Only task-related
● Time-boxed
● Always
● (+ TDD)
Refactoring can go on forever => focus, time-box. Task related => in code that
matters most now/in near future. (We: 1/3 every task devoted to refactoring.)
14. Refactoring: Improving the Design of Existing
Code
Martin Fowler
Working Effectively with Legacy Code
Michael Feathers
Behead Your Legacy Beast: The Mikado
Method
D. Brolund, O. Ellnestam