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 [2013-01-15 21:02] – evidence, relations, origin christian | principles:murphy_s_law [2021-09-02 17:54] – old revision restored (2021-09-02 10:43) 65.21.179.175 | ||
---|---|---|---|
Line 17: | Line 17: | ||
===== Description ===== | ===== Description ===== | ||
- | Although often cited like that, Murphy' | + | Although often cited like that, Murphy' |
- | Ideally | + | Ideally, incorrect usage is strictly impossible. For example, this is the case when the compiler will stop with an error if a certain mistake is made. And in the case of user interface design, a design is better when the user cannot make incorrect inputs as the given controls won't let him. |
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 " | ||
- | Note that Murphy' | + | Note that Murphy' |
Line 37: | Line 37: | ||
This is a very general principle so there is a large variety of possible strategies to adhere more to this principle largely depending on the given design problem: | This is a very general principle so there is a large variety of possible strategies to adhere more to this principle largely depending on the given design problem: | ||
- | * 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]]) | + | * 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. (see [[principles:Don't Repeat Yourself]]) | + | * Avoid duplication and manual tasks, so necessary changes are not forgotten |
- | * Use polymorphism instead of repeated switch statements. | + | * Use polymorphism instead of repeated switch statements |
+ | * Use the same mechanisms wherever reasonably possible (see [[Uniformity Principle]]) | ||
+ | * Use consistent naming and models throughout the design (see [[Model Principle]]) | ||
* ... | * ... | ||
Line 47: | Line 49: | ||
===== Origin ===== | ===== Origin ===== | ||
- | The exact wording and who exactly coined the term, remains unknown. Nevertheless it can be stated that its origin is an experiment with a rocket sled conducted by Edward A. Murphy and John Paul Stapp. During this experiment some sensors | + | The exact wording and who exactly coined the term, remains unknown. Nevertheless, it can be stated that its origin is an experiment with a rocket sled conducted by Edward A. Murphy and John Paul Stapp. During this experiment, some sensors |
Line 55: | Line 57: | ||
/* * [[wiki: | /* * [[wiki: | ||
- | * [[wiki: | + | * [[wiki: |
/* * [[wiki: | /* * [[wiki: | ||
Line 66: | Line 68: | ||
==== Specializations ==== | ==== Specializations ==== | ||
- | * [[principles:Don't Repeat Yourself]] (DRY): Duplication is a typical example | + | * [[Don' |
- | * [[principles: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. |
- | * [[principles: | + | * [[Uniformity Principle]] (UP): A typical source |
==== Contrary Principles ==== | ==== Contrary Principles ==== | ||
- | * [[principles:Keep It Simple Stupid]] (KISS): On the one hand a simpler design is less prone to implementation errors. | + | |
==== Complementary Principles ==== | ==== Complementary Principles ==== | ||
- | * [[principles: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 is recognized early. | + | |
Line 86: | Line 88: | ||
===== Example ===== | ===== Example ===== | ||
+ | ==== Example 1: Parameters ==== | ||
+ | |||
+ | Suppose there are two methods of a string class '' | ||
+ | |||
+ | The following method signatures are a bad choice: | ||
+ | <code java> | ||
+ | replaceFirst(String pattern, 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. | ||
+ | |||
+ | So it is better to make parameter lists consistent: | ||
+ | <code java> | ||
+ | replaceFirst(String pattern, string replacement) | ||
+ | replaceAll(String pattern, string replacement) | ||
+ | </ | ||
+ | This is less error prone. When for example a call to '' | ||
+ | |||
+ | 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> | ||
+ | replaceFirst(Pattern pattern, string replacement) | ||
+ | replaceAll(Pattern pattern, string replacement) | ||
+ | </ | ||
+ | Here both methods expect a '' | ||
+ | <code java> | ||
+ | "This are a test." | ||
+ | </ | ||
+ | ((Note that in the Java API it would rather be '' | ||
+ | instead of | ||
+ | <code java> | ||
+ | "This are a test." | ||
+ | </ | ||
+ | The [[Keep It Simple Stupid|KISS-Principle]] is about this disadvantage. | ||
+ | |||
+ | ==== Example 2: Casts and Generics ==== | ||
+ | |||
+ | Another example for the application of Murphy' | ||
+ | |||
+ | <code java> | ||
+ | List l = new ArrayList(); | ||
+ | l.add(5); | ||
+ | return (Integer)l.get(0) * 3; | ||
+ | </ | ||
+ | |||
+ | This works but it makes a cast necessary and every cast circumvents type checking by the compiler. This means it is theoretically possible that during maintenance someone will make a mistake and store a value other than Integer in the list: | ||
+ | <code java> | ||
+ | l.add(" | ||
+ | </ | ||
+ | Murphy' | ||
+ | <code java> | ||
+ | List< | ||
+ | l.add(5); | ||
+ | return l.get(0) * 3; | ||
+ | </ | ||
+ | Here this mistake is impossible as the compiler only allows storing integers. | ||
+ | |||
+ | Note that the typecast is rather a symptom than the actual problem here. The problem is, that the '' | ||
Line 91: | Line 150: | ||
/* 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 99: | Line 158: | ||
* [[wp> | * [[wp> | ||
* [[wiki> | * [[wiki> | ||
- | * [[http:// | + |
principles/murphy_s_law.txt · Last modified: 2021-10-20 21:18 by christian