To achieve the next level of software productivity, programs should consist of off-the-shelf, interchangeable components that are produced by a network of independent software companies. In turn, programming languages will need to provide sub-languages for formulating independent components and enforceable contracts between them. Component sublanguages have received plenty of attention over the past few years with the development of rich module systems. As for contracts, language researchers have almost exclusively focused on types, which excludes properties that can only be checked at run-time.
Eiffel and iContract (a Java dialect) are related attempts to address this problem. They incorporate a notion of checkable contract. A contract consists of pre- and post-conditions on individual methods. Unfortunately, both systems blame the wrong component when objects are used as first-class data, an increasingly common programming style. At best, this misplaced blame misleads the programmer in his search for bugs; at worst, it destroys a company for the wrong reason.
In response to these failures, we are developing a semantic framework for contracts in Java. Specifically, we are analyzing what it takes to add contracts to Java's interfaces and to enforce them through compilation. The goal is to add contracts without changing Java's semantics and to guarantee that the contracts are enforced according to a programmer's expectations. The result is a subtle compromise. Future work is to determine changes to Java that would make it easier to add and to enforce contracts.
Joint work with: Robert B. Findler