Cloning Considered Harmful Considered Harmful

20
Cloning Considered Harmful Considered Harmful? presented by Nicolas Bettenburg 1

description

A presentation of Mike Godfrey's work I gave at a reengineering course.

Transcript of Cloning Considered Harmful Considered Harmful

Page 1: Cloning Considered Harmful Considered Harmful

Cloning Considered Harmful

Considered Harmful?

presented byNicolas Bettenburg

1

Page 2: Cloning Considered Harmful Considered Harmful

10-15% cloned!

2

Page 3: Cloning Considered Harmful Considered Harmful

Intentional e.g., Copy & Paste

Unintentional e.g., Language Idioms

{

}

3

Page 4: Cloning Considered Harmful Considered Harmful

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

Page 5: Cloning Considered Harmful Considered Harmful

Clones consideredharmful!

5

Page 6: Cloning Considered Harmful Considered Harmful

But Wait!Is that the right thing

to do?

6

Page 7: Cloning Considered Harmful Considered Harmful

Example: Cloning to experiment without risk

experimental

stable

7

Page 8: Cloning Considered Harmful Considered Harmful

Understand Reasonbehind duplicationbefore deciding!

8

Page 9: Cloning Considered Harmful Considered Harmful

Catalogue of High-Level Cloning Patterns

9

Page 10: Cloning Considered Harmful Considered Harmful

8 general cloning patterns

CustomizationTemplatingForking

10

Page 11: Cloning Considered Harmful Considered Harmful

Hardware Variations

Clone existing driver+ No risk of changing existing driver- Code growth~ Dead code can creep into system

11

Page 12: Cloning Considered Harmful Considered Harmful

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

Page 13: Cloning Considered Harmful Considered Harmful

Clone existing code and experiment+ Maintain stable code- Merging later may be difficult~ Consistent maintenance becomes difficult

Experimental Variations

13

Page 14: Cloning Considered Harmful Considered Harmful

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

Page 15: Cloning Considered Harmful Considered Harmful

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

Page 16: Cloning Considered Harmful Considered Harmful

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

Page 17: Cloning Considered Harmful Considered Harmful

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

Page 18: Cloning Considered Harmful Considered Harmful

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

Page 19: Cloning Considered Harmful Considered Harmful

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

Page 20: Cloning Considered Harmful Considered Harmful

Considering Cloning harmful in general can be harmful!

20