Foundations · L1Complexity and deep modules

Complexity and deep modules

Learn why code gets hard to change, and how to hide each hard decision behind a simple interface so one change stays in one place.

L1 Must-knowFoundations18 min read
Fact-checked by AI against cited sources · Human review pendingLast reviewed 8 Nov 2026 · How we check content
Section 1 of 8

What broke

A made-up story to show a common failure. Not about a real company.

This story is made up, but it is common. Meera works on the payments team of a grocery app. Every night, a job writes the day's invoices to a CSV file. A second job reads that file and pays the shops.

The writer builds each line with join(","). The payout job splits each line with split(",") and reads the amount from column 2. A finance report does the same split in a third place. Nobody planned it this way. Each engineer copied what worked.

Then the tax rules changed. Meera added a tax column after the id, in the writer. Her tests passed. The pull request was small and looked safe.

That night, the payout job read the tax as the amount. Hundreds of shops got paid only their tax. The report showed the wrong totals too. Finance found it the next morning.

The bug was not in Meera's change. It was in the design. The file format was a decision that three classes shared, and nothing in the code said so.

Section 2 of 8

The idea in simple words

John Ousterhout teaches software design at Stanford. He uses the word complexity for anything in the structure of a system that makes it hard to work on. 2 He adds that the reader of the code judges it, not the writer. 2

He names three symptoms. 2

  • Change amplification. A simple change needs edits in many places. Meera's tax column needed three.
  • Cognitive load. You must hold a lot of information in your head to make a change.
  • Unknown unknowns. You need to know something before a change, but it is not clear where to find it. You may not even know you need it. Ousterhout calls the worst case a crucial fact hidden in far-away code you have never heard of. 9

He names two causes. Dependencies: if one piece of code changes, another must change too. Obscurity: it is not clear how the code works or why. 2 No single choice makes a system complex. Thousands of small dependencies and obscurities add up. 2

The cure is old. In 1972, David Parnas proposed a way to split a system into modules. Make a list of the "difficult design decisions or design decisions which are likely to change." Then design each module "to hide such a decision from the others." 1 This is information hiding.

The key idea. Give each hard decision one owner. Hide it behind a small, simple interface that does a lot of work. Then a change to that decision stays inside one module.

Ousterhout calls this a deep module: a small interface with a lot of function behind it. A shallow module has a complex interface, or does little, or both. 3

Section 3 of 8

How it works

Step through the same format change in two designs. Use Next and Back, or the ← and → keys.

One file format change: three files to edit when the format leaks, one file when a deep module hides itA · Shallow: the format leaks B · Deep: one module hides it WriterPayout jobReportid,amt,dateid,amt,dateid,amt,dateall three know the column order updatedmust changemust changeone change, three filesmiss one: tax is read as amount WriterPayout jobReportInvoiceFilewrite(path, invoices) · read(path)hidden: id,amt,date hidden: id,tax,amt,date✓ one file changes SeniorPath
  1. Design A. The writer, the payout job and the report each build or split the CSV line themselves. All three know the column order: id, then amount, then date.
  2. A new tax column goes after the id. The writer is updated. The payout job and the report must change too. If someone misses one, it reads the tax as the amount.
  3. Design B. One module, InvoiceFile, owns the format. The other parts only call write(path, invoices) and read(path). The column order is hidden inside it.
  4. The same change now happens inside InvoiceFile only. The callers still get invoice objects, so none of them changes.
Step 1 of 4

Deep: Unix file I/O

Ousterhout's example of a deep interface is Unix file I/O. 3 You need only a few calls:

int fd = open("invoices.csv", O_RDONLY);
char buf[4096];
ssize_t n = read(fd, buf, sizeof buf);  // bytes read; 0 at end, -1 on error
close(fd);

Look at what you do not see. Before Unix, systems often had separate calls for sequential and random access, and different calls for each kind of device. 7 Unix uses the same calls for both kinds of access. The kernel keeps your position in the file. 7 Each read moves that position forward by the bytes it returned. 8 The kernel also hides its buffer cache and device differences. 7 Devices use the same basic calls as files: open, read, write, lseek (called seek in early Unix) and close. One extra call, ioctl, handles device-specific work. 3

Shallow: a wrapper that hides nothing

Now compare a wrapper like this one, written in TypeScript:

class RawFile {
  constructor(private fd: number) {}
  readBytes(buf: Buffer, off: number, len: number, pos: number) {
    return fs.readSync(this.fd, buf, off, len, pos);
  }
}

Every argument goes straight through. You still track the position yourself. You must learn one more name and get nothing back. Ousterhout says a class is shallow when calling it is not much easier than writing its code. 3 He lists pass-through methods like readBytes as a red flag. 3 Each layer should offer a different idea from the layers above and below it. 3

Information leakage

Information leakage is the opposite of information hiding. Implementation details are exposed, and other classes depend on them. 3 Meera's CSV format leaked into three classes. Ousterhout calls this kind "back-door leakage": it is not visible in the interface. 3

A common cause is splitting code by the order things happen: one class reads, the next one parses, the next one saves. 3 Parnas saw the same problem in 1972. His first design made each processing step a module. If the way lines were stored changed, every module had to change. 1 In his second design, "knowledge of the exact way that the lines are stored is entirely hidden from all but module 1." 1

The fix for the payments team is one module that owns the format:

interface InvoiceFile {
  write(path: string, invoices: Invoice[]): void;
  read(path: string): Invoice[];
}

The column order, quoting and escaping now live in one place. The payout job gets Invoice objects and never sees a comma.

Pull complexity down

When some complexity cannot be removed, put it inside the module, not on its callers. Ousterhout's words: "Let a few module developers suffer, rather than thousands of users." He also writes that a simple API matters more than a simple implementation. 3

One form of this is to handle a problem rather than pass it up. Each configuration setting you expose is a question for the user. Ousterhout asks: if you do not know the right value, how will a user or administrator find it? 3

Another form is to define errors out of existence. Shape the API so the error case has a normal meaning. For example, "delete this key" can simply succeed when the key is already gone. Fewer callers then need special handling. 4 He warns that it is easy to take this idea too far. 5 It is for cases that are not really errors. Real bugs should still fail loudly, as the error handling lesson explains.

General-purpose beats special-purpose

Ousterhout advises making classes "somewhat generic". Build only what you need today, but shape the interface so it could serve other uses. 3 His text editor example compares two APIs. 6 The special-purpose one has methods such as insertChar, backspace, delete and deleteSelection. The general one has two methods: insert(position, text) and delete(start, end). Both serve the editor's keys. He says the general approach gives a simpler and deeper interface. 3

Size is not the goal

Ousterhout calls small classes taken to the extreme classitis. Each class adds as little as it can. 3 He says classes of 200 to 2,000 lines are fine, and depth matters more than size. 3

This is where the honest debate starts. Robert Martin's Clean Code asks for very small functions. Between September 2024 and February 2025, he and Ousterhout discussed it and published the result as a written debate. 9 They agreed that modular design is good and that you can split code too far. 9 Martin argued that small, well-named methods show how an algorithm works, even at the cost of some entanglement. 9 He said that if he must err, he would rather err on the side of splitting, since you can always inline later. 9 Ousterhout worried that tiny methods become shallow and entangled: you must read one to understand another. 9 Martin summed it up: they both value splitting code, and both avoid entanglement, but "we disagree on the relative weighting of those two values." 9

So "deep" is a judgment, not a metric. Parnas also noted a cost. If each function in his second design were a separate procedure call, it could be much less efficient. He suggested having the assembler insert the code inline instead. 1

Section 4 of 8

Trade-offs

Design choiceEasy to change?CostUse it when
Deep module with a small interfaceYes Hidden decisions change in one place.More thought up front. Some calls may be slower.The decision is hard or likely to change.
Many small, shallow classesNo Each change crosses many interfaces.More names to learn, more jumping between files.Rarely. Merge them when they always change together.
Special-purpose APIYes , for today's case only.Grows a new method for each new need.Rarely. Ousterhout advises making classes somewhat generic instead. 3
Somewhat general APIYes New uses fit the same methods.A little more design time.Several callers, or a clear family of uses.
Expose every settingYes , for experts.Every caller must learn and choose values.The right value truly depends on the caller.

Simple rule: before you add a class or a method, ask what it hides. If the answer is "nothing", do not add it.

Section 5 of 8

At work: how a senior uses this

  • For each module, write one sentence: "This module hides ___." If you cannot fill the blank, the module is probably shallow.
  • In code review, look for the same knowledge in two places: a format, a table layout, a magic string, an order of steps. Ask: "If this changes, how many files change?" See reviewing code.
  • Count the files in a recent small change. If adding one field touched eight files, that is change amplification. Add it to your tech debt list with the count.
  • When a class just forwards calls to another class with the same arguments, merge them or give the upper one a real job.
  • When a caller must "remember to" do something, move that step inside the module.
  • Apply the same thinking to REST APIs: a small set of resources that hide your database layout.
Section 6 of 8

With AI

What to ask the agent

"List every place in this repo that reads or writes the invoice CSV format. For each one, show the line that depends on the column order."

"Find classes whose public methods only call one other method with the same arguments. List them, and say what each one adds, if anything."

"Propose one module that hides this file format. Show its interface first, with at most three methods. Then list every caller that must change."

What to check yourself

  • The agent's list of places is complete. Search for the format yourself, including SQL, scripts and tests.
  • The new interface really is smaller. An agent can add a wrapper layer that just renames things.
  • The agent did not split one clear function into many tiny ones to look "clean". Read the result top to bottom.
  • Errors that were removed by design are cases with a natural meaning, not bugs that now pass silently.
  • Behaviour is the same. Run the old tests before and after the change.
Section 7 of 8

Check yourself

1. You add one new field to orders. You have to edit the API handler, the database mapper, two reports and a CSV export. Which symptom of complexity is this?

Show answer

Change amplification A simple change needs edits in many places. That is change amplification.

2. Which class is the deepest?

Show answer

A class with 2 methods, save(order) and load(id), that hides the table layout, caching and retries. A deep module gives a lot of function for a small interface. The other two are shallow, and the third is made of pass-through methods.

3. Two classes both split a CSV line by commas and read column 3 as the amount. What is the best fix?

Show answer

Move all knowledge of the format into one module that returns parsed objects. This is information leakage. Bring the knowledge into one place, so a format change touches one module.

4. What do Ousterhout and Robert Martin agree on in their published debate?

Show answer

Modular design is good, and it is possible to split code too far. Their summary says they agree on both points. They disagree on how far to split code and on comments.

Your progress is saved only in this browser. Export it to keep it safe.

Was this clear?
Report a mistake (opens GitHub in a new tab)
Section 8 of 8

Go deeper

Show 9 sources and related lessons
  1. D. L. Parnas, “On the Criteria To Be Used in Decomposing Systems into Modules”, Communications of the ACM 15(12), December 1972, pp. 1053–1058 (opens in a new tab)
    The classic paper. Two ways to split the same small program, and which changes each one survives.
  2. John Ousterhout, “The Nature of Complexity”, CS 190 lecture notes, Stanford (Winter 2018) (opens in a new tab)
    Short notes on the three symptoms of complexity and its two causes.
  3. John Ousterhout, “Modular Design”, CS 190 lecture notes, Stanford (Winter 2018) (opens in a new tab)
    Deep and shallow classes, classitis, information hiding and leakage, general-purpose classes, pulling complexity down.
  4. John Ousterhout, “Exception Handling”, CS 190 lecture notes, Stanford (Winter 2018) (opens in a new tab)
    Why errors add complexity, and ways to reduce the places that must handle them.
  5. John Ousterhout, “Discussion of A Philosophy of Software Design”, CS 190 class notes, Stanford (Winter 2024) (opens in a new tab)
    The book's main ideas as a short checklist, with a warning not to take "define errors out of existence" too far.
  6. John Ousterhout, “Text Editor Example”, CS 190 lecture slides (APOSD), Stanford (Winter 2024) (opens in a new tab)
    Slide 2 puts a special-purpose and a general-purpose text editor API side by side.
  7. John Ousterhout, “The UNIX Time-Sharing System”, CS 190 class notes, Stanford (Winter 2024) (opens in a new tab)
    What Unix file and device I/O hid from programs, compared with the systems before it.
  8. Linux man-pages project, read(2) (opens in a new tab)
    The read system call, its return value and how it moves the file offset.
  9. John Ousterhout and Robert C. Martin, “A Philosophy of Software Design vs Clean Code” (GitHub, 2024–2025) (opens in a new tab)
    A long written debate on method length, comments and TDD, with code, and a summary of where they agree.

Related: Managing technical debt · Reviewing code written by humans and AI · REST API design · Error handling and defensive design

Next: error handling and defensive design. SOLID, coupling and cohesion builds on this one, and so will a later lesson on functional programming ideas. Related: managing technical debt, reviewing code written by humans and AI and REST API design.

Term

See full entry

Jump to a section

  1. 1What broke
  2. 2The idea in simple words
  3. 3How it works
  4. 4Trade-offs
  5. 5At work
  6. 6With AI
  7. 7Check yourself
  8. 8Go deeper