The Artima Developer Community
Sponsored Link

Heron-Centric: Ruminations of a Language Designer
Programming with Contracts
by Christopher Diggins
October 15, 2004
Summary
Programming with Contracts is a sofware development technique rapidly gaining in popularity but still somewhat misunderstood. I have been spending a lot of time lately writing about contracts and using them in the Heron standard library.

Advertisement

Programming with Contracts (PwC) is a technique of using contracts in software in order to detect and reduce the number of defects in software. This is done by explicitly stating design specifications in a manner which can be verified by the compiler. This is related to but is not the same thing as Design by Contract tm which is a technique for designing software. The difference can be likened to the differences between OOP and OOD, one compliments the other but either one can exist without the other.

The role of a contract is to explicitly express the assumptions, requirements and obligations of a class or function. A contract is made up of one or more clauses. There are three kinds of clauses:

A contract should never be violated in correct software. If a clause is ever violated, there is a defect in your software (or possibly your contract).

The sticky point for a lot of people is understanding precisely what constitutes a contractual violation. Exceptional conditions and system failures in of themselves are not bugs but simply error conditions. A bug would occur if the these conditions where not handled in a manner as specified in the design specification. If no specification exists, whether explicit or assumed, that alone in of itself is a defect of the gravest kind.

For more information on contracts I suggest starting with the following:

For those interested: keep an eye out for my article Programming with Contracts in C++ in an upcoming issue of Doctor Dobbs Journal.

Talk Back!

Have an opinion? Readers have already posted 15 comments about this weblog entry. Why not add yours?

RSS Feed

If you'd like to be notified whenever Christopher Diggins adds a new entry to his weblog, subscribe to his RSS feed.

About the Blogger

Christopher Diggins is a software developer and freelance writer. Christopher loves programming, but is eternally frustrated by the shortcomings of modern programming languages. As would any reasonable person in his shoes, he decided to quit his day job to write his own ( www.heron-language.com ). Christopher is the co-author of the C++ Cookbook from O'Reilly. Christopher can be reached through his home page at www.cdiggins.com.

This weblog entry is Copyright © 2004 Christopher Diggins. All rights reserved.

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use