ShtukbaseStandard

Code: deep modules after Ousterhout

code-deep-modules · version 0.1.0
Code6 norms2 checks

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

NormWhat holdsLevelEnforcer
DM-R01A module is deepSHOULDcheck shallow-modules
DM-R02No pass-through functionsSHOULDcheck pass-through
DM-R03A decision is known to one moduleSHOULDjudge judges/information-hiding.md
DM-R04Errors are designed outSHOULDjudge judges/errors-out.md
DM-R05Complexity goes downMAYjudge judges/complexity-down.md
DM-R06A comment says what the code does notMAYjudge 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:

KeyDefaultWhat it means
minExports6from how many public functions on, look at a module's depth (DM-R01)
minDepth8lines 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

IDNormLevelModeEnforcer
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

NameWhat it doesFileWhen
shallow-modulesA module is deep
norm DM-R01
checks/shallow_modules.ts
check
pass-throughNo pass-through functions
norm DM-R02
checks/pass_through.ts
check
reviewA prompt for a reviewing agent over the package norms: by diff or by filesactions/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.

Package files 8

They go into .shtukbase/packages/code-deep-modules/; actions run from there.