All laws

§ 104Maintainability

Programming as Theory Building

A program's design lives in the heads of the people who built it, and the code and documents carry only part of it, so once those people are gone, changes tend to erode the design even with full documentation in hand.

Peter Naur

Keep in mind

Code stays maintainable only while someone can say why it is the way it is

What to do

When a system changes hands, plan an overlap: the new owners make real changes while the old team reviews them, and the handover ends when the old team stops catching patches that fight the design. Before merging code from a generator or a contractor, have the person who will own it explain why it is shaped the way it is; if nobody can, treat it as unowned. When a program's team is gone, Naur's advice is to discard the old text and let the new team solve the problem afresh, which he expects to cost no more than reviving it; where a rewrite is out of reach, rebuild the theory by pairing on real changes before restructuring anything.

Why it happens

Peter Naur argued that programming is mainly the programmers building up a theory of the matters at hand: how the program maps onto the world it serves, why each part is the way it is, and how a new demand fits into it. That knowledge stays with the people, "any documentation being an auxiliary, secondary product." In one case he describes, a second group extending a compiler had full documentation, annotated program texts, written design discussion and personal advice from the original authors, and still proposed patches that "effectively destroyed its power and simplicity"; the original group spotted them instantly. About ten years later, after others had changed it without that guidance, the original structure was "still visible, but made entirely ineffective by amorphous additions of many different kinds." Naur's conclusion: "The death of a program happens when the programmer team possessing its theory is dissolved," and rebuilding the theory merely from the documentation is "strictly impossible." Code accepted from a generator that nobody on the team has reasoned through is likely to start out in that state.

When it stops applying

Fake the Rational Design: Parnas and Clements argue for writing the design down as if it had been derived rationally and keeping that record current with every change, so new programmers do not have to depend completely on the old staff; where people move on often, a maintained record is a safer bet than counting on who stays.

Source

Peter Naur, Programming as Theory Building (Microprocessing and Microprogramming, 1985) — programming as building "a certain kind of insight, a theory, of the matters at hand", the compiler case, "The death of a program happens when the programmer team possessing its theory is dissolved.", and revival from documentation being "strictly impossible". The counter-force is from David L. Parnas & Paul C. Clements, A Rational Design Process: How and Why to Fake It (IEEE Transactions on Software Engineering, 1986) — "When new programmers join the project they do not have to depend completely on the old staff for their information."

Read the source

Portrait: Eriktj, CC BY-SA 3.0 · Wikimedia Commons

Cite this

Hammurabi, § 104, “Programming as Theory Building.” https://kanywst.github.io/hammurabi/laws/programming-as-theory-building/

BibTeX
@misc{hammurabi-programming-as-theory-building,
  title  = {Programming as Theory Building},
  author = {{Hammurabi contributors}},
  note   = {Hammurabi, § 104},
  url    = {https://kanywst.github.io/hammurabi/laws/programming-as-theory-building/}
}

Text under CC BY-SA 4.0: credit Hammurabi and link the article.

Read in a column

Related laws

Suggest a correction on GitHub