Contract-based design
This invited talk was delivered at the University of York in February 2021. Here’s a link to the YouTube playlist of all the lectures.
Contracts: an overview
Contracts will make you a stronger software developer. They change your thinking, actions, and values. As you internalize the contract metaphor, you’ll look at software differently.
You will apply logic to source code, not just animate code in your head. You will write contracts in your code, so both you and your team benefits. You will reward clean code and designs, not short-term hacking.
Contractual thinking applies to any kind of programming language, So you can use it with C, Java, Python, Haskell, or anything else.
It’s a transformation that takes time and effort, but the investment is worth it.
Slides:
Contracts: Bridging logical and procedural thinking
We can think about programs procedurally or logically. By the end of this talk, you will:
- Understand procedural and logical thinking
- Reason about code both ways
- See how contracts bridge them
- Appreciate how logic scales up better
Slides:
Contracts simplify tests
Tests are enormously helpful. They let you know that your code is working as expected. They make refactoring less stressful.
When your code has a contract, it’s easier to test. Writing a contract is no extra work. In fact, the effort of writing contracts saves testing effort.
Slides:
Contracts simplify designs
It’s hard to become a good software designer. If wishes were horses, beggars would ride. If just wanting to be good made it so, we’d all be good at designing software.
It’s frustrating to be told “just make the design simple”. How, exactly, do you do that?
By the end of this talk, you’ll see:
- How contracts reveal messy designs
- How they help separation of concerns
- How they help communicate the design
Contracts aren’t foolproof, but they guide you to simpler designs.
Slides:
Contracts separate interface from implementation
You enjoy the interface-implementation split on abstract datatypes (List, Set, Map, …). That’s because they have contracts. You can enjoy that split on your code too!
Slides:
Contracts and functional programming
There are different overall approaches to programming, like object-oriented (OO) and functional programming (FP). Contracts and FP have a lot of similarities. A few ideas from FP can help you write better contracts
- Think about domains and ranges
- Simplify contracts by seeking totality, purity, immutability
- Split impure methods
These ideas apply to OO programming too.
Slides:
Contracts improve code review
Code reviews are the norm in big tech companies. Alongside them are coding standards (ie style guides). I think contracts are a great addition. Let’s see how contracts help a team during code review.
Slides:
Thinking fast with contracts
It’s possible to become a master at software design, but you must set your expectations correctly. Many things in modern life are packaged like factoids: 5-minute abs, and even “minute physics”.
But – Mastery takes time. Mastering contractual design is a great investment. It’s the best way I know to become good at software design
Slides: