CSC/ECE 517 Fall 2007/wiki2 9 kk: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 33: Line 33:


=== General Software Design ===
=== General Software Design ===
[http://www.ddj.com/blog/cppblog/archives/2007/10/the_principle_o.html DDJ] has an article which introduces the user to applying the principle of least surprise to general software design by using an example of arrays in language called APL. A very basic introduction and some examples can be found [http://c2.com/cgi/wiki?PrincipleOfLeastAstonishment here].  
[http://www.ddj.com/blog/cppblog/archives/2007/10/the_principle_o.html DDJ] has an article which introduces the user to applying the principle of least surprise to general software design by using an example of arrays in language called APL. A very basic introduction and some examples can also be found [http://c2.com/cgi/wiki?PrincipleOfLeastAstonishment here].  


=== API Design ===
=== API Design ===

Revision as of 18:35, 24 October 2007

Principle of Least Astonishment

The principle of least astonishment states that when you are presented with different outcomes, one should always pick the outcome of least ambiguity or surprise. The principle has applications in a lot of fields. This wiki serves as a guide for the reader to understand more about this principle on the web. The principle of least astonishment goes by different names depending on the field of application like the element of least surprise, Occam's Razor etc.


Examples

The simplest example is in programming where the name of a function does not indicate its functionality.

int add(int a, int b)
{
   return (a*a+b*b);
}

The function above is supposed to add two numbers and return the sum but actually returns the sum of squares of the two numbers which would surprise the programmer who is using it. Applying the principle of least astonishment, we can either rename the function to indicate its functionality or we can rewrite the functionality itself to correspond to its name.

int sum_of_squares(int a, int b)
{
   return (a*a+b*b);
}

or

int add(int a, int b)
{
   return a+b
}

Application in Programming

General Software Design

DDJ has an article which introduces the user to applying the principle of least surprise to general software design by using an example of arrays in language called APL. A very basic introduction and some examples can also be found here.

API Design

The principle of least astonishment also plays an important role in API or library design. For example, when designing libraries or API's we want functions which does what the function name implies it will do. Steven's Tech Talk has a very good introduction to proper API design using the principle of least astonishment.

User interface design

The principle of least astonishment is used a lot in user interface design. Joel Spolsky has an article introducing user interface design using the principle of least astonishment. The article looks at a lot of examples of using the element of least surprise by comparing user interface design in Windows and Macintoshes.

A more general introduction to the application of the principle of least astonishment to UI design can be found here.

Webpage Design

Webpage design like UI design also finds the application of the principle of least astonishment. IBM has an excellent article on how this can be done.

Applications in Other Fields

The principle of least astonishment also finds a lot of applications in other fields though it might be referred to by a different name.

1. Occam's Razor is commonly used to explain phenonmena in such a way that the explanation makes the fewest assumptions possible. In other words it can be paraphrased as "All things being equal, the simplest solution tends to be the right one."

2. This paper looks at applying the principle of least astonishment to verification of digital circuits.

3. This page looks at applying the principle of least astonishment to riding bicycles in traffic.

External Links

Wikipedia Tao Of Programming