Chapter 5. Programming by Contract

Structuring code so that it’s testable, whereby increasing its probability of being tested isn’t the only way to aim for correct software. Another approach would be to go down the road of formal methods, that is, mathematical proofs. In this chapter, we examine yet another alternative, which is modeling the software as transactions between a client and supplier, who agree on a contract that forces them to uphold certain obligations to each other (see Figure 5.1). In exchange, both get some benefits. If the contract is violated, the application stops. For such an approach to be effective, the contract must be constantly checked at runtime, as opposed to running a suite of tests now and then or proving a fact ...

Get Developer Testing: Building Quality into Software now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.