IP Library Granted Patent US 8,250,524
Granted Patent B2
US 8,250,524 · App. 11/963,346 · Granted Aug 21, 2012

Contract programming for code error reduction

Assignee: Microsoft Corporation
View Patent ↗
Loading inventors, assignments & file history…
Monitor This Case
Get email alerts when status or documents change.
Order Certified Copies
Most orders are placed with the USPTO same day — all within 24 business hours.
Order via The Patent Place →
Pre-filled with this patent's details
Quick Facts
Patent No.
US 8,250,524
App. No.
11/963,346
Granted
Aug 21, 2012
Kind
B2
Abstract

In one embodiment, a computer system provides an application programming interface (API) for augmenting an application API. A computer system receives software code written in a second programming language indicating a user's intention to augment an application API with contracts from a contract API written in a first programming language. The software code includes a reference to the contract API. The contracts include assertions indicating appropriate use of the application API. The computer system accesses portions of the contract API according to the reference in the software code and compiles the received software code and the referenced portions of the contract API into an intermediate language (IL) version of the software code. The IL version is in an intermediate language common to both the first programming language and the second programming language. The IL version includes the assertions indicating appropriate use of the application API.

Claims (31)

1. At a computer system, a method for adding an executable contract to a method such that when the method is called, the executable contract is also executed to ensure that the method is called according to one or more rules specified in the contract, the method comprising:

an act of receiving source code that includes a call to a method of a first class as well as a call to a method of a contract class, the contract class providing methods for ensuring that the call to the method of the first class is performed in accordance with one or more rules specified as input to the call to the method of the contract class;

an act of compiling the received source code into intermediate language code that includes code for implementing the method of the first class as well as code for implementing the method of the contact class which is configured to be executed to verify that the one or more rules are met whenever the method of the first class is called and to report whether the one or more rules are met;

an act of storing the intermediate language code;

an act of executing the intermediate language code, wherein when the method of the first class is executed, the method of the contract class is also executed to verify whether the one or more rules are met; and

an act of reporting to a user via a user interface whether the one or more rules were met during the execution of the method of the first class.

2. The method of claim 1 , further comprising an act of statically checking the intermediate language code to verify whether the one or more rules are met.

3. The method of claim 1 , wherein the contract class is extensible to enable new methods to be added to the contract class to enable new kinds of contracts to be written.

4. The method of claim 1 , further comprising an act of automatically generating documentation for the first class based on the added contract.

5. The method of claim 1 , wherein contracts written using the contract class are persisted for a plurality of downstream tools.

6. The method of claim 1 , wherein the one or more rules include one or more of the following: preconditions, postconditions, lock declarations, checked exceptions, usage protocols and object invariants.

7. The method of claim 6 , wherein the one or more rules comprises a pre-condition to the method of the first class, and wherein the act of executing the intermediate language code comprises executing the method of the contract class upon entering the method of the first class to verify that one or more parameters of the method of the first class meet one or more conditions specified in the pre-condition.

8. The method of claim 6 , wherein the one or more rules comprises a post-condition to the method of the first class, and wherein the act of executing the intermediate language code comprises executing the method of the contact class upon exiting the method of the first class to verify that a return value of the method of the first class meet one or more conditions specified in the post-condition.

9. The method of claim 6 , wherein the one or more rules comprises an object invariant, and wherein executing the intermediate language code comprises executing the method of the contract class to verify that each type of the first class meets one or more conditions specified in the object invariant.

10. The method of claim 1 , wherein the contract class is written in a different programming language than the first class.

11. A computer program product comprising one or more physical storage devices having stored thereon computer executable instructions which when executed perform a method for adding an executable contract to a method such that when the method is called, the executable contract is also executed to ensure that the method is called according to one or more rules specified in the contract, the method comprising:

an act of receiving source code that includes a call to a method of a first class as well as a call to a method of a contract class, the contract class providing methods for ensuring that the call to the method of the first class is performed in accordance with one or more rules specified as input to the call to the method of the contract class;

an act of compiling the received source code into intermediate language code that includes code for implementing the method of the first class as well as code for implementing the method of the contact class which is configured to be executed to verify that the one or more rules are met whenever the method of the first class is called and to report whether the one or more rules are met; and

an act of storing the intermediate language code;

an act of executing the intermediate language code, wherein when the method of the first class is executed, the method of the contract class is also executed to verify whether the one or more rules are met; and

an act of reporting to a user via a user interface whether the one or more rules were met during the execution of the method of the first class.

12. A computer system, the computer system comprising:

one or more processors; and

one or more computer-readable storage media storing computer-executable instructions representing a software design tool that is executed by the one or more processers to perform the following:

an act of receiving source code that includes a call to a method of a first class as well as a call to a method of a contract class, the contract class providing methods for ensuring that the call to the method of the first class is performed in accordance with one or more rules specified as input to the call to the method of the contract class;

an act of compiling the received source code into intermediate language code that includes code for implementing the method of the first class as well as code for implementing the method of the contact class which is configured to be executed to verify that the one or more rules are met whenever the method of the first class is called and to report whether the one or more rules are met;

an act of storing the intermediate language code;

an act of executing the intermediate language code, wherein when the method of the first class is executed, the method of the contract class is also executed to verify whether the one or more rules are met; and

an act of reporting to a user via a user interface whether the one or more rules were met during the execution of the method of the first class.

13. The system of claim 12 , wherein the contract class is written in a different programming language than the first class.

14. The system of claim 12 , wherein the one or more rules are at least one of a precondition, a postcondition, a lock declaration, a checked exception, a usage protocol, and an object invariant.

Assignments (2)
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Dec 9, 2014
From: MICROSOFT CORPORATION
To: MICROSOFT TECHNOLOGY LICENSING, LLC
Reel/Frame 034542/0001 →
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Dec 28, 2007
From: BARNETT, MICHAEL; FAHNDRICH, MANUEL A.; GRUNKEMEYER, BRIAN M.; SCHULTE, WOLFRAM
To: MICROSOFT CORPORATION
Reel/Frame 020298/0034 →
Continuity (1)
Related Publication 20090164973A1 · Jun 25, 2009