Deep modules: design the interface, delegate the implementation
After this lesson you can describe the interface of a small tool (what goes in, what comes out and what it refuses) before delegating how it works. Advanced and optional for the beginner path. Before you start: complete the previous lesson.
Interface first
A module is a part of a system with one job. Its interface is everything a user of it must know. A deep module does a lot behind a small interface; a shallow one makes you know almost as much as it hides.
You decide the interface because it carries your intent. You can delegate the inside, then test it from outside. This is sometimes called a gray box: you do not write every line, but you can still look inside when risk or a failed check calls for it.
Worked example (fictional)
A library needs a late-fee tool.
- Shallow: the caller gives opening days, holidays, daily rate, cap and dates, in order. Every caller must know every rule.
- Deep: the caller gives a loan and today's date; the tool gives a fee and a reason. Holidays, rate and cap stay inside.
Interface: input a due date and a return date; output an amount of zero or more, and a reason; refuses a missing date or a return earlier than the loan. Checks: on time gives zero; one day late gives one daily rate; a missing date is refused, not guessed.
When the cap changes, callers of the deep version do not change.
Practice
Choose a small tool, such as "turn a list of names into badges". On one page write one sentence of purpose, inputs, outputs, two refusals and four checks (normal, edge, unusual, refused). Do not describe how it works. Then ask Claude, in Plan mode: "Using only this page, list what you would have to guess."
Finished when every guess is answered on the page or marked "does not matter", and no line says how to build it.
Common errors and recovery
- The interface lists internal steps. Move them out unless the user needs them.
- Ten settings. Choose defaults and keep only what users must decide.
- Refusals are missing. Ask what should happen with empty, repeated and impossible input.
Check yourself
Two designs give the same result. Design 1 needs six settings from every caller. Design 2 needs two and keeps the other rules inside, with checks. Which is easier to delegate, and what must you still do?
Answer. Design 2: there is less to agree on and it can be tested from outside. You must still check its behavior and look inside where a mistake would be costly. "Nothing, it is hidden" is the tempting error: hidden is not the same as correct.
Further study (optional)
The attached talk develops this idea for developers.
Sources
The distinction between deep and shallow modules is generally credited to John Ousterhout's A Philosophy of Software Design; that book was not opened for this lesson. Example and exercise are original. Opened 2026-11-25:
