principles:murphy_s_law
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:murphy_s_law [2020-10-12 12:41] – old revision restored (2013-03-19 16:58) 159.69.186.191 | principles:murphy_s_law [2020-10-12 14:36] – old revision restored (2013-01-16 15:38) 159.69.186.191 | ||
---|---|---|---|
Line 23: | Line 23: | ||
It is not always possible to design a system in such a way. But as systems are built and used by humans, one should strive for such " | It is not always possible to design a system in such a way. But as systems are built and used by humans, one should strive for such " | ||
- | There are different kinds of possible errors that can and according to ML eventually will occur in some way: Replicated data can get out of sync, invariants can be broken, preconditions can be violated, interfaces can be misunderstood, | + | Note that Murphy' |
- | + | ||
- | Note that Murphy' | + | |
Line 40: | Line 38: | ||
* Make use of static typing, so the compiler will report faults | * Make use of static typing, so the compiler will report faults | ||
- | * Make the design simple, so there will be fewer implementation defects (see [[Keep It Simple Stupid|KISS]]) | + | * Make the design simple, so there will be fewer implementation defects (see [[Keep It Simple Stupid]]) |
* Use automatic testing to find defects | * Use automatic testing to find defects | ||
- | * Avoid duplication and manual tasks, so necessary changes are not forgotten (see [[Don' | + | * Avoid duplication and manual tasks, so necessary changes are not forgotten (see [[Don' |
* Use polymorphism instead of repeated switch statements | * Use polymorphism instead of repeated switch statements | ||
- | * Use the same mechanisms wherever reasonably possible (see [[Uniformity Principle|UP]]) | + | * Use the same mechanisms wherever reasonably possible (see [[Uniformity Principle]]) |
- | * Use consistent naming and models throughout the design (see [[Model | + | * Use consistent naming and models throughout the design (see [[Model Principle]]) |
- | * Avoid Preconditions and Invariants (see [[Invariant Avoidance | + | |
* ... | * ... | ||
- | |||
- | |||
- | ===== Caveats ===== | ||
- | |||
- | See section [[#contrary principles]]. | ||
Line 79: | Line 71: | ||
* [[Easy to Use and Hard to Misuse]] (EUHM): Because of ML an interface should be crafted so it is easy to use and hard to misuse. EUHM is the application of ML to interfaces. | * [[Easy to Use and Hard to Misuse]] (EUHM): Because of ML an interface should be crafted so it is easy to use and hard to misuse. EUHM is the application of ML to interfaces. | ||
* [[Uniformity Principle]] (UP): A typical source of mistakes are differences. If similar things work similarly, they are more understandable. But if there are subtle differences in how things work, it is likely that someone will make the mistake to mix this up. | * [[Uniformity Principle]] (UP): A typical source of mistakes are differences. If similar things work similarly, they are more understandable. But if there are subtle differences in how things work, it is likely that someone will make the mistake to mix this up. | ||
- | * [[Invariant Avoidance Principle]] (IAP): Invariants are statements that have t be true in order to keep a module in a consistent state. ML states that eventually an invariant will be broken resulting in a hard to detect defect. IAP states that invariants should therefore be avoided. So IAP is the application of ML to invariants. | ||
==== Contrary Principles ==== | ==== Contrary Principles ==== | ||
- | * **[[Keep It Simple Stupid]] (KISS)**: On the one hand a simpler design is less prone to implementation errors. In this aspect KISS is similar to ML. On the other hand it is sometimes more complicated to make a design " | + | * **[[Keep It Simple Stupid]] (KISS)**: On the one hand a simpler design is less prone to implementation errors. In this aspect KISS is similar to ML. On the other hand it is sometimes more complicated to make a design " |
==== Complementary Principles ==== | ==== Complementary Principles ==== | ||
- | * **[[Fail Fast]] (FF)**: Sometimes it is impossible to actually prevent an error. In such a case it is advisable to fail fast so the error is recognized early. | + | * **[[Fail Fast]] (FF)**: Sometimes it is impossible to actually prevent an error. In such a case it is advisable to fail fast to the mistake |
Line 95: | Line 86: | ||
- | ===== Examples | + | ===== Example |
==== Example 1: Parameters ==== | ==== Example 1: Parameters ==== | ||
Line 103: | Line 94: | ||
The following method signatures are a bad choice: | The following method signatures are a bad choice: | ||
<code java> | <code java> | ||
- | replaceFirst(String pattern, | + | replaceFirst(String pattern, |
- | replaceAll(String replacement, | + | replaceAll(String replacement, |
</ | </ | ||
Eventually someone will mix up the order of the parameters leading to a fault in the software which is not detectable by the compiler. | Eventually someone will mix up the order of the parameters leading to a fault in the software which is not detectable by the compiler. | ||
Line 110: | Line 101: | ||
So it is better to make parameter lists consistent: | So it is better to make parameter lists consistent: | ||
<code java> | <code java> | ||
- | replaceFirst(String pattern, | + | replaceFirst(String pattern, |
- | replaceAll(String pattern, | + | replaceAll(String pattern, |
</ | </ | ||
This is less error prone. When for example a call to '' | This is less error prone. When for example a call to '' | ||
Line 117: | Line 108: | ||
But here still one could mix up the two string parameters. Although this is less likely, as having the substring to look for first is " | But here still one could mix up the two string parameters. Although this is less likely, as having the substring to look for first is " | ||
<code java> | <code java> | ||
- | replaceFirst(Pattern pattern, | + | replaceFirst(Pattern pattern, |
- | replaceAll(Pattern pattern, | + | replaceAll(Pattern pattern, |
</ | </ | ||
Here both methods expect a '' | Here both methods expect a '' |
principles/murphy_s_law.txt · Last modified: 2021-10-20 21:18 by christian