Post on 27-Jun-2015
description
Cloning Considered Harmful
Considered Harmful?
presented byNicolas Bettenburg
1
10-15% cloned!
2
Intentional e.g., Copy & Paste
Unintentional e.g., Language Idioms
{
}
3
A A
B
A
B
A
B
A
B
1.1 1.2 1.3 1.4.0 1.4.1
Cloning = additional maintenance effort
4
Clones consideredharmful!
5
But Wait!Is that the right thing
to do?
6
Example: Cloning to experiment without risk
experimental
stable
7
Understand Reasonbehind duplicationbefore deciding!
8
Catalogue of High-Level Cloning Patterns
9
8 general cloning patterns
CustomizationTemplatingForking
10
Hardware Variations
Clone existing driver+ No risk of changing existing driver- Code growth~ Dead code can creep into system
11
Clone existing code and fix low level platform interaction+ Avoid complexity of virtualization layer- Hard to propagate bug fixes~ Ensure consistent behavior of all clones
Platform Variations
12
Clone existing code and experiment+ Maintain stable code- Merging later may be difficult~ Consistent maintenance becomes difficult
Experimental Variations
13
Cloning due to language constraints+ Make reuse of trusted code possible- Increased maintenance (close evolution)~ Explicit and rigorous linking of all duplicates
Boiler-plating
14
Clone reoccurring call sequences+ Learn from code and reduce effort- Degradation of Code Quality~ Changes to API require maintenance of all clones
API/Library Protocols
15
Idioms provide standardization+ Selfdocumenting and improve comprehensibility- Faulty implementations are easily overlooked~ no long term issues
Language Idioms
a = malloc(64);if (a == null) {out(“Error!”);
}...
16
Clone to provide work arounds+ Clone buggy code and fix- Source of the bug is not addressed~ Remove clone when bug is fixed
Bug Workarounds
...a = sqroot(81);if (a != 9) {a = 9;
}...
...a = sqroot(81);...
17
Clone to reuse and adapt existing solutions+ Less effort needed- Long-term cost outweighs short-term benefit~ Cost of refactoring rises over time
Replicate & Specialize
18
Conclusions
•Templating requires synchronization•Variation requires monitoring of changes•Forking need outlining
•Not all clones require refactoring•Some situations warrant the effort•Measure risk vs. long-term cost
19
Considering Cloning harmful in general can be harmful!
20