Design By Contract in C

Charlie Mills creates a Design-By-Contract library for C (which could equally be used for C++ with minor changes) in his most recent OnLamp article. DBC views functions and methods as contractual agreements between the functional caller and the object/module providing the function. Charlie’s implementation is a really neat idea using Object Constraint Language (OCL)to describe:

  • function preconditions
  • function postconditions
  • type and function invariants

The implementation is hacked up using Ruby and Racc and is available here.. I’m currently playing around with DBC for Java using iContracts and I’ll post the inevitable success stories here soon…