SLIDE 1 Strategic Code Deletion
Michael Feathers
R7K Research & Conveyance
SLIDE 2
SLIDE 3
(everyone wants to delete code)
SLIDE 4
When Can We Delete Code?
SLIDE 5
SLIDE 6
SLIDE 7
Varieties of Useless Code
SLIDE 8
SLIDE 9
SLIDE 10
And another one..
Low Value code
No wikipedia entry (yet) :-)
SLIDE 11
Coverage
SLIDE 12
gprof
SLIDE 13
https://nylas.com/blog/performance/
SLIDE 14
Mutation Testing
SLIDE 15
Feature Probe
SLIDE 16
scythe_probe(“marker”);
Feature Probe
SLIDE 17 scythe_probe(“marker”);
Feature Probe
- Record marker
- Periodically check for absence of marker
SLIDE 18
Feature Probe
SLIDE 19 Pricer Scan Devices Promotions Reconciliation Inventory Edge Client
- Accept gift card
- Split charge (2 customers)
- Select home delivery
- Produce/Meat by weight
- Daily specials
- Weekly specials
- Restock perishable schedule
- Record invalid scans
- Change till procedure
- Cashier login
- Register reconcile
SLIDE 20
The Cost Case
SLIDE 21 Unreachable Code Dead Code Low Value Code
Compiler Errors / Warnings Mutation Testing Feature Probes / Stack Sampling / Coverage Delete on Detect Delete on Detect Strategize
SLIDE 22
- Delete Unreachable and Dead Code on Detection
- Disable Low
Value Code at entry points
Strategy
SLIDE 23
Human in the Loop for Internal Pruning
SLIDE 24
Systematic Rewrite
SLIDE 25
Most rewrites are motivated by technology or architectural change
SLIDE 26
Most rewrites are motivated by technology or architectural change
“Cleaning rewrites” should be focused and selective
SLIDE 27 (from Jez Humble)
SLIDE 28 Key Actions for Rewrite
- Can you find all inputs and outputs?
- Are you reducing conditionality?
- Are you scoped for Characterization
Testing?
SLIDE 29
Searching for Pinch Points
SLIDE 30
Characterization Testing
Tests you write to describe the current behavior of your system
SLIDE 31
Characterization Testing
Tests you write to describe the current behavior of your system
How is this different from other testing?
SLIDE 32
SLIDE 33
SLIDE 34
SLIDE 35
SLIDE 36
SLIDE 37
SLIDE 38
SLIDE 39
SLIDE 40
SLIDE 41
SLIDE 42
SLIDE 43
Is this a bug?
SLIDE 44
Simple Case Heuristics
SLIDE 45
- Start with “x”
- Use expressive (long) names
- Rename to tell a story
- Make the call on bugs
- Be curious!
Simple Case Heuristics
SLIDE 46
- Start with “x”
- Use expressive (long) names
- Rename to tell a story
- Make the call on bugs
- Be curious!
Simple Case Heuristics
SLIDE 47
- Start with “x”
- Use expressive (long) names
- Rename to tell a story
- Make the call on bugs
- Be curious!
Simple Case Heuristics
SLIDE 48
- Start with “x”
- Use expressive (long) names
- Rename to tell a story
- Make the call on bugs
- Be curious!
Simple Case Heuristics
SLIDE 49
- Start with “x”
- Use expressive (long) names
- Rename to tell a story
- Make the call on bugs
- Be curious!
Simple Case Heuristics
SLIDE 50
What was our goal?
SLIDE 51
SLIDE 52
SLIDE 53 ✔ balance ✔ gallons ✘ RESIDENTIAL_MIN ✘ RESIDENTIAL_BASE
SLIDE 54
Tooling Varies
SLIDE 55
SLIDE 56
SLIDE 57
SLIDE 58
Reducing Conditionality
SLIDE 59
Apache
SLIDE 60
Microsoft IIS
SLIDE 61
if (…) { … }
SLIDE 62
SLIDE 63
SLIDE 64
Edge-Free Programming
SLIDE 65
SLIDE 66
Redund Until Replace
SLIDE 67
Redund Until Replace
When you have a pure section of code that is a replacement, run it in parallel and log if there are differences
SLIDE 68
Conclusion
SLIDE 69 Pricer Scan Devices Promotions Reconciliation Inventory Edge Client
- Accept gift card
- Split charge (2 customers)
- Select home delivery
- Produce/Meat by weight
- Daily specials
- Weekly specials
- Restock perishable schedule
- Record invalid scans
- Change till procedure
- Cashier login
- Register reconcile
SLIDE 70