shtukbasehub

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.

Packagecode-deep-modulesv0.1.016 files

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

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.