They mention the Eiffel language on the web page you mentioned. The Eiffel people (
cf Meyer B,
Object-Oriented Software Construction 2/e Upper Saddle River NJ: Prentice-Hall (1998), page 333
ff) use the concept of Design-by-Contract (TM), which builds on early work by C A R Hoare.
A function/procedure/subroutine/method is considered correct if the following applies:-
It is considered to consist of three parts, {P} A {Q}.P is the precondition, Q is the postcondition, and A is the actual coding.P has to be true before the processing starts.The coding then must ensure and guarantee that Q will be true after the coding starts.There is also an invariant, which must be true before and after every method (but maybe not during methods) Example of preconditions: when depositing money in the bank, the amount recorded is greater than zero.
Example of postconditions: when depositing money, the total in the account has increased by the amount of deposit.
Example of invariant: in a circle the area is PI*r^2 within the bounds of precision available from the arithmetic.
You use the precondition assertion principally to check that the parameters passed are correct, and the postcondition assertion to check that the method is working as expected. You will find precondition assertions
passim in the API docs; look at the three-argument constructor for
java.awt.Color, and you find it has a precondition assertion in. It might not look like an assertion, but it is printed as:-
Throws:
IllegalArgumentException - if are, g or b are outside of the range 0.0 to 1.0, inclusive.
As Eric Daly says
You use an assertion to make darn sure that anything you assume to be true in your code is actually true.
Then, as Joanne Neal implies, once you are happy it is working and you can let the code loose on an unsuspecting world, you disable all the assertions.
I know most people think "are" is not short for red the way g and b are short for green and blue, but the website computer thinks I am using the letter one after Q as a prohibited abbreviation.