The programming by contract is a Paradigme of programming in which the course of the treatments is governed by rules. These rules, called assertions, form a contract which specifies the responsibilities between the customer and the supplier for a piece of software code. It is a method of Programmation semi formal of which the principal goal is to reduce the number of bug S in the programs.
Historically, the programming by contract was introduced by Bertrand Meyer into his language Eiffel going back to 1985, which was inspired by the Notation Z created by Jean-Raymond Abrial.
The principle is to specify what must be true at a given time of the execution of a program. It should not be thought that this paradigm obliges to carry out effective tests of the rules during the execution: these tests are only one in the ways of making sure that the rules are complied with. There exist three types of assertions:
Precondition: The condition which must be checked by the customer before the launching of a given treatment. This condition must guarantee that the execution of the treatment is possible without error.
The language used to write the conditions is important. It must have a value of truth; in other words it is a logical and one uses the Boolean expressions in general language host. To be able to often express more things one there assistant a means so that the postconditions can refer to the old value of the variable modified by the treatment. Finally one can add the quantifiers of the logical first order.
These assertions are written directly in the source code of the program and make it possible to provide an additional documentation on the direction which the code has. That thus makes it possible to describe the semantic program.
Several computer programming languages implements this paradigm like Eiffel, D, Lisaac, Spark, VDM. Modules exist for other languages, like JContractor for Java.
This technique has a very strong bond with the formal methods making it possible to certify correct a program. The three rules above are in fact a traditional form of specification of the program.
But, contrary to the methods of evidence of programs, one will not seek to show explicitly that the specification is well carried out by the program. This part is left at the discretion of the customer and the supplier.
Nevertheless one often installs mechanisms of tests of the rules during the execution to check their validity. One can use in addition to the unit tests to check the assertions in an elegant way. But that makes it possible to in no case to be sure only the rules are all the time valid. Indeed it would be necessary, most of the time, to carry out an infinity of different executions to check all the possible cases.
But it is recognized that this method nevertheless makes it possible to obtain software of better quality and to accelerate the phases of débuggage.
| Random links: | International federation of associations of librarians and institutions | Wu Zhang | Fishing out of entry in the LNH 2007 | Herbert Murerwa | Mijajlovac |