Code: deep modules after Ousterhout
The school of John Ousterhout ("A Philosophy of Software Design", 2018): deep modules, hidden knowledge, no pass-through layers, errors designed out, complexity pushed down; two heuristics and four judges.
About the package
The school. The main enemy is complexity: whatever makes a system hard to understand and to change. A module is good when behind a simple interface it hides a lot of work (it is "deep"). Shallow modules, thin wrappers and decisions leaking between modules multiply complexity.
The author. John Ousterhout (Stanford). Source: John Ousterhout, "A Philosophy of Software Design", Yaknyam Press, 2018; 2nd edition 2021. The norms below retell the ideas in our own words; they are not quotes.
When to take it. Libraries, cores, long-lived services, where a module's interface is read more often than its code.
When not to take it. Small scripts; code whose interface is set from outside (framework handlers, an implementation of someone else's protocol).
Norms
| Norm | What holds | Level | Enforcer |
|---|---|---|---|
| DM-R01 | A module is deep | SHOULD | check shallow-modules |
| DM-R02 | No pass-through functions | SHOULD | check pass-through |
| DM-R03 | A decision is known to one module | SHOULD | judge judges/information-hiding.md |
| DM-R04 | Errors are designed out | SHOULD | judge judges/errors-out.md |
| DM-R05 | Complexity goes down | MAY | judge judges/complexity-down.md |
| DM-R06 | A comment says what the code does not | MAY | judge judges/comments-why.md |
All norms are in observe mode: the checks print findings and pass, the judges are a procedure for the reviewer. A check you trust on your code is moved by the owner to mode: enforce in the norm's page, and then a finding fails shtuk check.
How to connect
shtuk install <path>/apps/standard/packages/code-deep-modules --dir <project>
shtuk check --dir <project>
shtuk run code-deep-modules review # a prompt for the reviewer over the uncommitted change
shtuk run code-deep-modules review --diff main..HEAD
shtuk run code-deep-modules review src/a.ts src/b.py
The package requires norms-core and code-lib (the shared code-parsing library and shared settings). It is installed on top of Basic.
Settings
Which code to read is the shared page /norms/code.md of the code-lib package: roots (roots), exclusions (exclude), languages, whether to read tests. This package's thresholds are the page /norms/code/code-deep-modules.md:
| Key | Default | What it means |
|---|---|---|
minExports | 6 | from how many public functions on, look at a module's depth (DM-R01) |
minDepth | 8 | lines of code per public function; fewer means the module is shallow (DM-R01) |
The same page has its own exclude list (path masks from the project root). One place is released by the comment code-allow: <check name> on its line or the line above.
Honestly about the checks
The checks are rough heuristics: regular expressions and bracket parsing for TypeScript/JavaScript, Python and Rust, with no parsers and no dependencies. They err both ways, which is why they stand in observe. The meaning of a norm is held by the judge; the heuristic only shows where to look. 2 checks, 4 judges.
Norms 6
| ID | Norm | Level | Mode | Enforcer |
|---|---|---|---|---|
| DM-R01 | A module hides a lot of work behind a small interface: with minExports or more public functions (6), each has at least minDepth lines of code (8). |
SHOULD | observes | sensor |
| DM-R02 | There is no function that only passes its parameters unchanged to another function. |
SHOULD | observes | sensor |
| DM-R03 | Every design decision (a format, a protocol, the order of steps, a data layout) is known to one module; others use it through the interface. |
SHOULD | observes | judge |
| DM-R04 | The interface is chosen so that there are as few special cases and exceptions as possible; errors that can be avoided by definition are not thrown outward. |
SHOULD | observes | judge |
| DM-R05 | A module takes complexity on itself: the interface has reasonable defaults, and callers do not need to know settings that the module can decide on its own. |
MAY | observes | judge |
| DM-R06 | Comments on interfaces and on non-obvious places explain what and why, which cannot be seen from the code; a comment does not retell the line below it. |
MAY | observes | judge |
"Blocks": the enforcer stops a violation. "Observes": it only notes it. Level MUST means required; SHOULD means yes by default.
Actions 3
| Name | What it does | File | When |
|---|---|---|---|
| shallow-modules | A module is deep norm DM-R01 | checks/shallow_modules.ts | check |
| pass-through | No pass-through functions norm DM-R02 | checks/pass_through.ts | check |
| review | A prompt for a reviewing agent over the package norms: by diff or by files | actions/review.ts | shtuk run |
shtuk check runs the checks; shtuk run code-deep-modules <name> runs any action. "After install" actions run by themselves only if the package comes from a trusted source.
Pages 7
They go into the project at these paths.
- /norms/code/
- Settings: Code: deep modules after Ousterhout page
- /norms/rules/code-deep-modules/
- A module is deep DM-R01
- No pass-through functions DM-R02
- A decision is known to one module DM-R03
- Errors are designed out DM-R04
- Complexity goes down DM-R05
- A comment says what the code does not DM-R06
Package files 8
They go into .shtukbase/packages/code-deep-modules/; actions run from there.