User Tools

Site Tools


principles:keep_it_simple_stupid

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
Next revisionBoth sides next revision
principles:keep_it_simple_stupid [2013-01-30 10:06] – +HC christianprinciples:keep_it_simple_stupid [2021-09-02 14:03] – old revision restored (2021-05-19 10:25) 65.21.179.175
Line 12: Line 12:
  
   * [[contexts:Object-Oriented Design]]   * [[contexts:Object-Oriented Design]]
 +  * [[contexts:Architecture]] 
 +  * [[contexts:User Interface Design]]
  
 ===== Principle Statement ===== ===== Principle Statement =====
Line 46: Line 47:
   * Avoid general solutions needing parameterization. A specific solution will suffice.   * Avoid general solutions needing parameterization. A specific solution will suffice.
   * ...   * ...
 +
 +
 +===== Caveats =====
 +
 +See section [[#contrary principles]].
  
  
Line 52: Line 58:
 The principle was coined by the American engineer Kelly Johnson referring to the requirement that a military aircraft should be repairable with a limited set of tools under combat conditions ((Ben R. Rich: //[[http://www.nap.edu/html/biomems/cjohnson.pdf|Clarence Leonard (Kelly) Johnson 1910—1990: A Biographical Memoir]]//)). The principle was coined by the American engineer Kelly Johnson referring to the requirement that a military aircraft should be repairable with a limited set of tools under combat conditions ((Ben R. Rich: //[[http://www.nap.edu/html/biomems/cjohnson.pdf|Clarence Leonard (Kelly) Johnson 1910—1990: A Biographical Memoir]]//)).
  
-The principle of striving for simple solutions sometimes is also called "(rule of) simplicity"((Eric S. Raymond: //[[http://www.catb.org/~esr/writings/taoup/html/ch01s06.html#id2877917|The Art of Unix Programming]]//)) which was also prominently stated by Tony Hoare in his Turing Award lecture: "I conclude that there are two ways of constructing a software design: One way is to make it so simple that there are \textit{obviouslyno deficiencies and the other way is to make it so complicated that there are no \textit{obviousdeficiencies. The first method is far more difficult."((Tony Hoare: //[[http://awards.acm.org/images/awards/140/articles/4622167.pdf|The Emperor’s Old Clothes / The 1980 ACM Turing Award Lecture]]//))+The principle of striving for simple solutions sometimes is also called "(rule of) simplicity"((Eric S. Raymond: //[[http://www.catb.org/~esr/writings/taoup/html/ch01s06.html#id2877917|The Art of Unix Programming]]//)) which was also prominently stated by Tony Hoare in his Turing Award lecture: "I conclude that there are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult."((Tony Hoare: //[[http://awards.acm.org/images/awards/140/articles/4622167.pdf|The Emperor’s Old Clothes / The 1980 ACM Turing Award Lecture]]//))
  
  
Line 58: Line 64:
 /* Comment out what is not applicable and explain the rest: */ /* Comment out what is not applicable and explain the rest: */
 /*  * [[wiki:Proposed]]*/ /*  * [[wiki:Proposed]]*/
-/*  * [[wiki:Examined]]*/+/*  * [[wiki:Questioned]]*/
  
-  * [[wiki:Accepted]]: This principle is widely known and accepted in practice. See for example Jargon File: //[[http://www.catb.org/jargon/html/K/KISS-Principle.html|KISS Principle]]// 
  
-/*  * [[wiki:Questioned]]*/+[[wiki:Accepted]]: This principle is widely known and accepted in practice. See for example Jargon File: //[[http://www.catb.org/jargon/html/K/KISS-Principle.html|KISS Principle]]// 
 + 
 +[[wiki:Examined]]: While the preference for simple solutions can be considered trivially intuitive, there has been some work relating simplicity or rather complexity and certain quality attributes. But as there is no universally applicable complexity metric and not even a commonly agreed upon clear definition of simplicity, research is bound to examine certain aspects of KISS independently.  
 + 
 +The following hypotheses can be stated: 
 +  - Simpler solutions are faster to implement. 
 +  - Simpler solutions yield less implementation faults (which reduces testing effort). 
 +  - Simpler solutions are easier to maintain, i.e. detecting and correcting defects is more effective and efficient. 
 +  - Simpler solutions yield more reliable software, i.e. less defects show up after releasing the software. 
 + 
 +All these hypotheses can be examined with respect to different complexity metrics. 
 + 
 +Hypothesis 1 can be regarded true by definition. If the solution cannot be implemented fast, it is not simple.  
 + 
 +Though hypotheses 2 and 3 are not true by definition but they can be regarded intuitively clear. Nevertheless there is some research. In ((Virginia R. Gibson and James A. Senn: //[[http://dl.acm.org/citation.cfm?id=62073|System Structure and Software Maintenance Performance]]//)) a system was improved in two steps resulting in three variants of the same system. Several metrics show that the improvements reduced complexity. 36 programmers with varying experience conducted three different maintenance tasks and their performance was measured. The results indicate that the improvements also improved maintainability. Several other studies support the correlation between complexity and maintainability((Chris F. Kemerer: //[[http://link.springer.com/article/10.1007%2FBF02249043?LI=true|Software complexity and software maintenance: A survey of empirical research]]//)). 
 + 
 +Furthermore software cost estimation techniques are partly based on complexity judgments((Barry W. Boehm: //Software Engineering Economics//, IEEE)). So complexity---although this normally relates the complexity of the problem and not to the complexity of the solution---is a known cost factor which may be accounted to maintenance. 
 + 
 +Lastly hypothesis 4 is likely to be false. Several studies relating complexity metrics and post-release reliability show that module size in lines of code predicts reliability at least as good as the McCabe metric (also called cyclomatic complexity) ((see Albert Endres, Dieter Rombach: //A Handbook of Software and Systems Engineering//, p. 168ff.)). Assuming cyclomatic complexity correctly depicts the complexity of a module, reliability should not the reason for applying KISS.
  
  
Line 83: Line 106:
   * **[[Murphy's Law]] (ML)**: The ultimate reason behind KISS is to increase maintainability and reduce the introduction of defects. But following KISS blindly by always using the simplest solution may also lead to //reduced// maintainability when Murphy's Law is not considered.   * **[[Murphy's Law]] (ML)**: The ultimate reason behind KISS is to increase maintainability and reduce the introduction of defects. But following KISS blindly by always using the simplest solution may also lead to //reduced// maintainability when Murphy's Law is not considered.
   * [[Model Principle]] (MP): There are often simpler ways to build a software system than to model and mirror the real world behavior, which frequently means having more objects and more complicated structures. Nevertheless it is advisable to do so anyway.   * [[Model Principle]] (MP): There are often simpler ways to build a software system than to model and mirror the real world behavior, which frequently means having more objects and more complicated structures. Nevertheless it is advisable to do so anyway.
-  * [[High Cohesion]] (HC): Reducing complexity by not introducing further modules typically leads to a lower cohesion. 
  
 ==== Complementary Principles ==== ==== Complementary Principles ====
Line 93: Line 115:
  
  
-===== Example =====+===== Examples =====
  
-FIXME+==== Example 1: Fuzzy Simplicity ====
  
 +Simplicity is a blurry, partly subjective measure. Sometimes it is difficult to tell what is simpler. The following example shows that:
 +
 +<code java>
 +public String weekday1(int dayOfWeek)
 +{
 +    switch (dayOfWeek)
 +    {
 +        case 1: return "Monday";
 +        case 2: return "Tuesday";
 +        case 3: return "Wednesday";
 +        case 4: return "Thursday";
 +        case 5: return "Friday";
 +        case 6: return "Saturday";
 +        case 7: return "Sunday";
 +        default: throw new IllegalArgumentException("dayOfWeek must be in range 1..7");
 +    }
 +}
 +
 +public String weekday2(int dayOfWeek)
 +{
 +    if ((dayOfWeek < 1) || (dayOfWeek > 7))
 +        throw new IllegalArgumentException("dayOfWeek must be in range 1..7");
 +
 +    final String[] weekdays = {
 +        "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
 +
 +    return weekdays[dayOfWeek-1];
 +}
 +</code>
 +
 +Both methods do exactly the same thing. They return a string representing the weekday. Just the implementation is different. Both versions may be seen as simpler than the other depending on the view taken. ''weekday2'' has less statements and less execution branches. Complexity metrics measuring these aspects (e.g. the [[glossary:cyclomatic complexity]]) will therefore prefer ''weekday2''.
 +
 +On the other hand ''weekdays1'' uses less language features (just switch, return, and exceptions whereas ''weekdays2'' needs if, arrays, arithmetic, return, and exceptions). Furthermore in ''weekdays1'' the relation between input and output can be seen directly and it's clear how it works by just seeing the method. But for understanding ''weekday2'' there are more details to think about. This is especially true for the range check at the beginning and the index computation in the ''return'' statement. Clearly this is not particularly difficult but these are aspects which are more difficult than in the other version of the method.
 +
 +So it's not objectively clear which of the two implementations KISS prefers without saying which complexity metric to apply. But this ambiguity is not a problem since principles are not meant to be unambiguous and objective. Eventually a human developer has to decide which solution to implement and the principles only give guidelines.
 ===== Description Status ===== ===== Description Status =====
 /* Choose one of the following and comment out the rest: */ /* Choose one of the following and comment out the rest: */
Line 110: Line 167:
   * [[http://www.catb.org/~esr/writings/taoup/html/ch01s06.html#id2877917|The Art of Unix Programming: Rule of Simplicity]]   * [[http://www.catb.org/~esr/writings/taoup/html/ch01s06.html#id2877917|The Art of Unix Programming: Rule of Simplicity]]
  
 +===== Discussion =====
 +
 +Discuss this wiki article and the principle on the corresponding [[talk:principles:Keep It Simple Stupid|talk page]].
principles/keep_it_simple_stupid.txt · Last modified: 2021-10-20 21:09 by christian