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.
Code: deep modules after Ousterhout
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.