Previous page | Next page | Contents | Home Obix pragmatics

Program with checks!

The concept of Program with checks is similar to Design by contract which has been developed by Bertrand Meyer and is integrated in the language Eiffel. Although it is an invaluable concept for developing reliable software, most languages don't support it. The idea behind is easy: Protect software against programming errors by providing conditions (contracts) that must be respected by anyone at any time.

To understand the importance of this pragmatic let's look at a real world example and see what could happen in a world without checks. Buddy dreams of his own house and has a clear idea about how it should be constructed. Although Buddy never studied architecture he draws a plan, writes specifications and delivers all this data to a constructor who immediately starts the project, without checking Buddy's input and without any agreement on the price and delivery conditions. Obviously, the chances for a successful project are close to zero. It is easy to imagine any deficiencies and obscurities like cold rooms in winter, dark rooms, rooms without doors or even a collapsing house. Another example of preprogrammed problems would be an employee working for a company without an employment contract.

Clearly, a world without contracts guaranteeing a healthy cooperation between two parties would end up in a disaster.

Surprisingly, a large amount of software is written without checks, which is often a main reason for fragile software. Program with checks has been integrated into Obix from the ground up. 4 different kinds of checks exist:

Attribute checks: They protect attributes against any illegal values (e.g. a customer identifier being empty)

Input checks: They protect a script against any illegal input value (e.g. a negative integer value as index for retrieving an item from an indexed list)

Output checks: They detect any illegal values returned by a script (e.g. a character position in a string which is greater than the length of the string)

Script checks: They can be inserted in any script at any point and are used whenever the programmer asserts a condition that must always be fulfilled at run-time. If the assertion doesn't hold, a run-time error will be generated. Script conditions are useful for detecting logical errors in scripts, such as errors in an algorithm; loop variant and invariant violations; etc.

Concrete examples of Program with checks can be found in the tutorial.


Previous page | Next page | Contents | Home October 2004