principles:principle_of_least_surprise
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:principle_of_least_surprise [2021-03-25 15:44] – old revision restored (2020-12-10 11:55) 95.216.172.193 | principles:principle_of_least_surprise [2021-09-02 14:15] – old revision restored (2021-09-02 10:25) 65.21.179.175 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Principle Of Least Surprise (PLS) ====== | + | jakooll |
===== Variants and Alternative Names ===== | ===== Variants and Alternative Names ===== | ||
* Principle of Least Astonishment (PLA) | * Principle of Least Astonishment (PLA) | ||
* May also be referred to as " | * May also be referred to as " | ||
+ | * Acronyms sometimmjjhlhjkhjkhjkhkhjkhes include the " | ||
===== Context ===== | ===== Context ===== | ||
/* fill in contexts here: */ | /* fill in contexts here: */ | ||
- | * [[contexts: | + | * [[contexts: |
+ | * [[contexts: | ||
+ | * [[contexts: | ||
+ | * [[contexts: | ||
- | + | ===== Principle Statement | |
- | ===== Definition | + | |
> In interface design, always do the least surprising thing.((Eric S. Raymond: // | > In interface design, always do the least surprising thing.((Eric S. Raymond: // | ||
+ | |||
===== Description ===== | ===== Description ===== | ||
+ | Never surprise the user. An interface should behave exactly as the user thinks it behaves. What surprises the user depends on the kind of interface (user interface, module interface) and the type of user (end user, fellow programmer, maintainer). The central idea of PLS is to think about how the user would want to use the interface. | ||
===== Rationale ===== | ===== Rationale ===== | ||
+ | Surprises are always a potential source for frustration. A user wants to be in control of the system. If the system does not behave as intended, the user gets disappointed and has to determine how to get the system do what it should do. On the other hand a system that behaves according to the users wishes is pleasant to use. | ||
+ | |||
+ | Secondly when everything works as expected, the user will make fewer mistakes. In case of a user interface this means that the user is more effective and in case of a module interface the software will have fewer defects. | ||
+ | |||
+ | |||
+ | ===== Strategies ===== | ||
+ | |||
+ | * Separate methods that change an object (commands) from methods asking the object a question (queries) (see [[Command-Query Separation|CQS]]) | ||
+ | * This especially means that a query method should not alter the observable object state | ||
+ | * Name all modules in a way that clearly communicates what the module is and does | ||
+ | * Names of classes shall be nouns representing a specific (real-world) concept (see [[Model Principle|MP]]) | ||
+ | * Names of '' | ||
+ | * Names of command methods shall be verbs (in imperative form) | ||
+ | * Names of query methods shall start with get- or is- | ||
+ | * Names of mathematical functions or the like shall be named by the respective concept (like '' | ||
+ | * ... | ||
+ | * Avoid " | ||
+ | * [[When in doubt, use brute force]]((http:// | ||
+ | * Tend to use the first solution that comes in mind | ||
+ | |||
+ | ===== Caveats ===== | ||
+ | |||
+ | See section [[#contrary principles]]. | ||
===== Origin ===== | ===== Origin ===== | ||
+ | |||
+ | The precise origin is unknown. Probably it's // | ||
===== Evidence ===== | ===== Evidence ===== | ||
/* Comment out what is not applicable and explain the rest: */ | /* Comment out what is not applicable and explain the rest: */ | ||
- | / | + | |
- | [[wiki: | + | / |
- | [[wiki: | + | /*[[wiki: |
- | [[wiki: | + | |
+ | [[wiki: | ||
+ | |||
+ | /*[[wiki: | ||
Line 38: | Line 70: | ||
==== Generalizations ==== | ==== Generalizations ==== | ||
+ | |||
+ | * [[Easy to Use and Hard to Misuse]] (EUHM): A module is easy to use if there is no surprise in how it works. | ||
==== Specializations ==== | ==== Specializations ==== | ||
+ | * [[Command-Query Separation]] (CQS) | ||
==== Contrary Principles ==== | ==== Contrary Principles ==== | ||
==== Complementary Principles ==== | ==== Complementary Principles ==== | ||
- | * [[principles: | + | * [[Fail Fast]] (FF): FF is about what a module should do in the case of error. PLS on the other hand is about how the module should behave normally. Furthermore it normally is not a surprise that a module fails when there is an error but a module that doesn' |
- | * [[principles: | + | * [[Model Principle]] (MP): PLS is mainly about how module identifier and module behavior relate to each other. MP tells that modules named according to the model are least surprising. |
- | * [[principles: | + | * [[Uniformity Principle]] (UP): When applying PLS, UP should also be considered for naming modules. |
==== Principle Collections ==== | ==== Principle Collections ==== | ||
+ | {{page> | ||
{{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 69: | Line 105: | ||
* [[wiki> | * [[wiki> | ||
* Joshua Bloch: // | * Joshua Bloch: // | ||
+ | |||
+ | ===== Discussion ===== | ||
+ | |||
+ | Discuss this wiki article and the principle on the corresponding [[talk: |
principles/principle_of_least_surprise.txt · Last modified: 2021-10-18 22:15 by christian