User Tools

Site Tools


principles:rule_of_explicitness

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
principles:rule_of_explicitness [2013-03-17 18:02] christianprinciples:rule_of_explicitness [2021-10-18 22:06] (current) – +++ restored +++ christian
Line 7: Line 7:
 ===== Context ===== ===== Context =====
 /* fill in contexts here: */ /* fill in contexts here: */
-  * [[contexts:Object-Oriented Design]]  +  * [[contexts:Object-Oriented Design]] 
 +  * [[contexts:API Design]] 
 +  * [[contexts:Implementation]]
  
 ===== Principle Statement ===== ===== Principle Statement =====
Line 17: Line 18:
 ===== Description ===== ===== Description =====
  
 +Solutions often differ in the level of explicitness. A feature can be implemented explicitly or it can be a side-effect of the implementation of another feature or a more general functionality. The same applies to module communication. A module can invoke another module directly or there can be various forms of indirections like events or observers.
  
 +RoE states that explicit solutions are better than implicit ones. Indirection, side-effects, configuration files, implicit conversions, etc. should be avoided.
 ===== Rationale ===== ===== Rationale =====
  
 +If something is realized explicitly, it is easier to understand. Implicit solutions require the developer to have a deeper understanding of the module as it is necessary to "read between the lines". Implicit solutions also tend to be more complex. So explicit solutions are assumed to be less error-prone and easier to maintain.
  
 ===== Strategies ===== ===== Strategies =====
Line 30: Line 34:
     * Avoid highly configurable modules. Instead implement varying behavior explicitly.     * Avoid highly configurable modules. Instead implement varying behavior explicitly.
   * Explicitly state which module to use   * Explicitly state which module to use
-    * Avoid importing all classes of a given package/namespace and import the needed classes explicitly. In Java this means not to specify wildcard imports like ''import package.*'' and to avoid static imports. Similarly in Python this means not to use wildcard imports.+    * Avoid importing all classes of a given package/namespace and import the needed classes explicitly. In Java this means not to specify wildcard imports like ''import package.*'' and to avoid static imports. Similarly in Python this means not to use wildcard imports. In C++, do not import entire namespaces (e.g. do not use ''using namespace std;'').
     * Avoid ''with'' statements in Delphi and other languages having constructs that let you invoke methods without explicitly stating the associated object.     * Avoid ''with'' statements in Delphi and other languages having constructs that let you invoke methods without explicitly stating the associated object.
   * Explicitly name parameters   * Explicitly name parameters
Line 80: Line 84:
   * [[Generalization Principle]] (GP): RoE often results in specific solutions. Generality often requires stating something implicitly.   * [[Generalization Principle]] (GP): RoE often results in specific solutions. Generality often requires stating something implicitly.
   * [[Low Coupling]] (LC): Direct communication typically has the disadvantage of a higher coupling. Indirection reduces coupling but creates implicit/indirect communication paths.    * [[Low Coupling]] (LC): Direct communication typically has the disadvantage of a higher coupling. Indirection reduces coupling but creates implicit/indirect communication paths. 
- +  * [[Don't Repeat Yourself]] (DRY): Following RoE sometimes leads to duplication.
 ==== Complementary Principles ==== ==== Complementary Principles ====
  
   * [[Keep It Simple Stupid]] (KISS): Explicit solutions are often also simpler.   * [[Keep It Simple Stupid]] (KISS): Explicit solutions are often also simpler.
-  * [[Murphy's Law]] (ML):The typical reason for RoE is to avoid unnecessarily complicated solutions and possibilities for defects. Don'loose that goal out of sight.+  * [[Murphy's Law]] (ML):The typical reason for RoE is to avoid unnecessarily complicated solutions and possibilities for defects. Don'lose sight of that goal.
   * [[Model Principle]] (MP): RoE states that [[anti-patterns:primitive obsession]] shall be avoided. Instead more specific types should be used in parameter lists. MP makes this even clearer: In object-orientation objects instead of plain integers or strings are used.   * [[Model Principle]] (MP): RoE states that [[anti-patterns:primitive obsession]] shall be avoided. Instead more specific types should be used in parameter lists. MP makes this even clearer: In object-orientation objects instead of plain integers or strings are used.
 +  * [[Law of Leaky Abstractions]] (LLA): Often abstractions create a level of implicitness. Abstraction leaks are one reason why explicit solutions can be considered preferable.
  
 ==== Principle Collections ==== ==== Principle Collections ====
Line 94: Line 97:
  
  
-===== 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:Stub]] +/*[[wiki:Stub]]*
-/*[[wiki:Incomplete]]*/+[[wiki:Incomplete]]
 /*[[wiki:Complete]]*/ /*[[wiki:Complete]]*/
  
Line 108: Line 111:
   * Martin Fowler: //[[http://martinfowler.com/ieeeSoftware/explicit.pdf|To Be Explicit]]//   * Martin Fowler: //[[http://martinfowler.com/ieeeSoftware/explicit.pdf|To Be Explicit]]//
   * Tim Peters: //[[http://www.python.org/dev/peps/pep-0020/|The Zen of Python]]//   * Tim Peters: //[[http://www.python.org/dev/peps/pep-0020/|The Zen of Python]]//
 +
 +===== Discussion =====
 +
 +Discuss this wiki article and the principle on the corresponding [[talk:principles:Rule of Explicitness|talk page]].
  
principles/rule_of_explicitness.1363539766.txt.gz · Last modified: 2013-05-20 12:46 (external edit)