principles:don_t_repeat_yourself
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
principles:don_t_repeat_yourself [2012-11-29 17:21] – [Context] christian | principles:don_t_repeat_yourself [2013-06-22 20:39] – christian | ||
---|---|---|---|
Line 10: | Line 10: | ||
* [[contexts: | * [[contexts: | ||
- | ===== Definition | + | ===== Principle Statement |
> "Every piece of knowledge must have a single, unambiguous, | > "Every piece of knowledge must have a single, unambiguous, | ||
Line 25: | Line 25: | ||
- | ===== Origin | + | ===== Strategies |
- | Andrew Hunt and David Thomas: // | + | * Add a new invokable module (a function, a method, a class, etc.) instead of duplicating code |
+ | * Use code generation when information has to be represented in multiple forms | ||
+ | * Use polymorphism to avoid repeatedly enumerating a set of possible solutions in if or switch statements | ||
+ | ===== Caveats ===== | ||
+ | |||
+ | See section [[#contrary principles]]. | ||
+ | |||
+ | |||
+ | ===== Origin ===== | ||
+ | {{page> | ||
===== Evidence ===== | ===== Evidence ===== | ||
/* Comment out what is not applicable and explain the rest: */ | /* Comment out what is not applicable and explain the rest: */ | ||
- | / | + | /* |
- | /*[[wiki: | + | |
- | [[wiki: | + | |
- | / | + | |
+ | |||
+ | /* | ||
Line 42: | Line 53: | ||
==== Generalizations ==== | ==== Generalizations ==== | ||
- | * [[principles: | + | * [[Murphy' |
==== Specializations ==== | ==== Specializations ==== | ||
- | * [[principles:Once And Only Once]]: This is the aspect of DRY which is concerned with the avoidance of (code) duplication. | + | * [[Once And Only Once]] |
+ | * [[Single Choice Principle]] (SCP): Duplication can also be duplication of information about a set of possibilities. The SCP is about this aspect. | ||
+ | * [[Write Code That Writes Code]]: This is the code generation aspect of DRY. | ||
==== Contrary Principles ==== | ==== Contrary Principles ==== | ||
- | * [[principles:Keep It Simple Stupid]]: Especially code generators can be very complex. | + | * [[Keep It Simple Stupid]] |
==== Complementary Principles ==== | ==== Complementary Principles ==== | ||
+ | * [[Generalization Principle]] (GP): A generalized solution avoids duplication. | ||
==== Principle Collections ==== | ==== Principle Collections ==== | ||
+ | {{page> | ||
+ | {{page> | ||
- | ===== Example | + | ===== Examples |
===== Description Status ===== | ===== Description Status ===== | ||
/* Choose one of the following and comment out the rest: */ | /* Choose one of the following and comment out the rest: */ | ||
- | [[wiki: | + | /*[[wiki: |
- | /*[[wiki: | + | [[wiki: |
/ | / | ||
Line 73: | Line 89: | ||
* [[wp> | * [[wp> | ||
* [[http:// | * [[http:// | ||
+ | |||
+ | ===== Discussion ===== | ||
+ | |||
+ | Discuss this wiki article and the principle on the corresponding [[talk: |
principles/don_t_repeat_yourself.txt · Last modified: 2021-10-18 21:27 by christian