A comparative study of programmer-written and automatically inferred contracts

Nadezhda Polikarpova, Ilinca Ciupa, Bertrand Meyer · Repository for Publications and Research Data (ETH Zurich) · 2012

Where do contracts — specification elements embedded in executable code — come from? To produce them, should we rely on the programmers, on automatic tools, or some combination? Recent work, in particular the Daikon system, has shown that it is possible to infer some contracts automatically from prgram executions. The main incentive has been an assumption that most programmers are reluctant to in vent the contracts themselves. The experience of contract supporting languages, notably Eiffel, disproves that as sumption: programmers will include contracts if given the right tools. That experience also shows, however, that the resulting contracts are generally partial and occasionally incorrect. Contract-inference tools provide the opportunity for studying objectively the quality of programmer-written con tracts, and for assessing of the respective roles of humans and tools. Working on an industrial base of contract equipped software, we applied Daikon to infer contracts, and compared the results with the already present contracts. We found that a contract inference tool can be used to strengthen programmer-written contracts, but cannot infer all contracts that humans write. The tool generates around five times as many relevant contract elements (assertions) as written by programmers; but it only finds about a half of those originally written by programmers. The study also uncovered strong correlations between the quality of inferred contracts and some other interesting code metrics.

Read the paper · More papers on PaperTik