← knowledge.oriz.in

Prefer deep modules — small interface, powerful implementation

rule rulesdevelopmentarchitecturemodulestesting

Deep modules over shallow

Ousterhout, A Philosophy of Software Design Ch. 4.

Definition

Shape Interface Implementation Hides
Deep Simple, narrow Complex, powerful Lots
Shallow Nearly as complex as impl Thin Nothing

Visual: deep = tall thin rectangle. Shallow = short wide rectangle. Interface = top edge. Implementation = area.

Goal: maximize hidden complexity per unit of exposed surface.

Why agents thrive on deep modules

Benefit Mechanism
Obvious test boundary Draw ring around module → meaningful test. Shallow module = ring around nothing.
Gray-box delegation Human pins interface. Agent free-fires on impl.
Fewer cross-module deps Narrow interfaces = fewer callers reasoning about internals.
Cache-friendly context Load one deep module + interface = enough. Load 20 shallow ones = context bloat.

Anti-patterns — shallow modules

Refactor question

Before splitting a module: can interface get simpler at cost of richer implementation?

If yes → merge, not split. Push complexity down, not sideways.

If no → split justified.

When shallow is OK

Everywhere else: deepen.

Source

Cross-refs