Chesterton’s Fence: Before You Take It Down, Find Out Why It Is There

By Sergey Nosov

16 November 2026

Everyone who joins a project walks into a field of fences. There is a delay nobody can explain, a check for a value that supposedly can never be null, and a firewall rule nobody remembers adding. Here is one in code, the file src/lookup.ts from a small demo repository I built for this article:

import { sleep } from './sleep';
import { lookup } from './vendor';

export async function lookupAll(
  ids: string[],
) {
  const found: unknown[] = [];
  for (const id of ids) {
    await sleep(1100);
    found.push(await lookup(id));
  }
  return found;
}

Every lookup waits 1,100 milliseconds before it calls the vendor. Delete the sleep line, and the batch finishes much sooner. Nothing in the file says why the line is there.

The tempting move is to delete it and see what happens. A better rule is almost a century old, and it has a name, Chesterton’s Fence: before you take a fence down, find out why it is there. Then decide.

This article applies that rule to the line above: where to look for the reason, where Git can mislead you, and what to do when no reason turns up. I ran every command on Git 2.55.0 and the tests on Vitest 5.1.0 with Node.js 26, in November 2026.

What Chesterton Wrote

The principle comes from “The Drift from Domesticity,” an essay in G. K. Chesterton’s 1929 book The Thing. He was writing about reforming institutions and laws, and he offered what he called “one plain and simple principle; a principle which will probably be called a paradox.” Here it is:

There exists in such a case a certain institution or law; let us say, for the sake of simplicity, a fence or gate erected across a road. The more modern type of reformer goes gaily up to it and says, “I don’t see the use of this; let us clear it away.” To which the more intelligent type of reformer will do well to answer: “If you don’t see the use of it, I certainly won’t let you clear it away. Go away and think. Then, when you can come back and tell me that you do see the use of it, I may allow you to destroy it.”

The next paragraph gives the reasoning:

The gate or fence did not grow there. It was not set up by somnambulists who built it in their sleep. It is highly improbable that it was put there by escaped lunatics who were for some reason loose in the street. Some person had some reason for thinking it would be a good thing for somebody. And until we know what the reason was, we really cannot judge whether the reason was reasonable.

Somnambulists are sleepwalkers. Two things in the passage are easy to miss. First, it does not say that the fence must stay. The reformer who comes back knowing its use may be allowed to destroy it. A few sentences later, Chesterton lists what that knowledge lets a person say: that the purposes “were bad purposes,” or “have since become bad purposes,” or “are purposes which are no longer served.” Second, the work of finding out belongs to the person who wants the change, not to whoever built the fence.

Chesterton’s real subject in the essay was the home, not software. But he wrote that the principle “applies to a thousand things, to trifles as well as true institutions,” and code qualifies. Nobody commits a line in their sleep. Software even offers a consolation: the reason is often written down somewhere.

A Fence That Came Down

One fence removal in software left a public record, almost line by line. In 2006, a Debian maintainer was dealing with warnings from Valgrind, a tool that detects memory errors, in programs that used OpenSSL. He pointed to OpenSSL’s random number generator, which was adding an uninitialized buffer to its pool, and to two lines in one file. Both were the same call, MD_Update(&m,buf,j);.

On 1 May 2006, he asked the OpenSSL developers’ mailing list about them: “What I currently see as best option is to actually comment out those 2 lines of code. But I have no idea what effect this really has on the RNG.”

A reply came a few hours later from an openssl.org address: “If it helps with debugging, I’m in favor of removing them.” Russ Cox, who analyzed the episode in Lessons from the Debian/OpenSSL Fiasco, counts two substantive replies and sums both up as “go ahead, remove the MD_update line.” The maintainer did.

On 13 May 2008, a Debian security advisory reported that the random number generator in Debian’s package was “predictable” because of “an incorrect Debian-specific change.” The first vulnerable version had been uploaded on 17 September 2006. The advisory recommended that all cryptographic key material generated by the affected versions on Debian systems be “recreated from scratch.”

Cox’s analysis, published eight days after the advisory, explains what happened. The two lines looked alike and did different jobs. One sat behind RAND_bytes, the function that hands out random bytes. It stirred the caller’s buffer, initialized or not, into the pool, and it was already compiled out for builds under Purify, a commercial tool of the same kind as Valgrind. It even carried a comment: “purify complains.” The other sat behind RAND_add, the function that mixes seed data into the pool. As quoted in the maintainer’s message, that line carried no comment.

“The fact that one instance wasn’t essential made it look like the other instance wasn’t essential,” Cox wrote. With the seed line gone, RAND_add no longer added anything to the pool, and the generator still ran. Cox identifies the process ID as the only remaining input that was even “a little unpredictable.” By his account, the ssh-keygen program on affected systems “could only generate 32,767 different possible SSH keys of a given type and size.”

The maintainer was not Chesterton’s careless reformer. He said plainly that he did not know what removing the lines would do, and, in Cox’s words, he “asked the experts for help, and was given bad information.” The story adds three things to Chesterton’s rule:

Start with the History

The delay in the demo has a history, and the history is the first place to look. Three commands do most of the work.

Who last changed these lines? git blame names the commit that last changed each line, and -L limits it to a range of lines:

git blame -w -L 8,10 src/lookup.ts

Each line of the output starts with a commit hash, and git show with that hash prints the commit’s message and its changes.

The -w option matters more than it looks. Git’s documentation says it makes blame “ignore whitespace when comparing the parent’s version and the child’s to find where the lines came from.” In the demo repository, a later commit re-indented the whole file. Without -w, blame pinned all three lines of the loop on that reformat. With it, the delay pointed at the commit that added it, and the lines around it pointed at the first commit.

The option has a limit. In a copy of the demo where the reformat also split the call across three lines, -w still blamed the reformat. git blame --ignore-rev, which skips a commit you name, pointed back at the commit that added the delay. The blame.ignoreRevsFile setting does the same for a list of commits kept in a file. GitHub documents that its blame view reads such a file when it is named .git-blame-ignore-revs and sits in the root of the repository.

Which commit introduced this text? git log -S, known as the pickaxe, is the tool for that. In the words of the documentation, it looks for differences that “change the number of occurrences” of a string in a file: a commit that added the text or removed it. Here it is on the delay, with two options that shorten the output:

$ git log -S "sleep(1100)" \
    --abbrev-commit --date=short
commit c2ce1fd
Author: Dana <dana@example.test>
Date:   2026-03-17

    Throttle vendor calls (#1042)

    The vendor allows one call per
    second per key. A burst at
    2 a.m. got our key suspended
    for a day. 1,100 ms leaves a
    margin.

That message is the sign on the fence. The incident is invented, like everything else in the demo. The point is the distance: when the author wrote the reason down, it is one command away.

How did this function get here? git log -L follows a range of lines, or one function, back through the commits that changed it, and it prints each change as a diff:

git log -L :lookupAll:src/lookup.ts

In the demo, it printed three commits, newest first: the reformat, the commit that added the delay, and the commit that created the function.

Then follow the trail. The (#1042) in the subject line is a pull request number. When a commit carries one, it leads to the pull request, and from there to the review discussion and any linked issue or work item. GitHub’s default message for a merge commit “includes the pull request number and title.” Microsoft says that when a pull request completes, Azure DevOps puts the pull request ID “at the beginning of the message” of the commits it generates. A repository setting added in 2026 can turn that off.

If the history is silent, ask the author, the team, or whoever owns the product. On a new project, asking is part of the job. Take the Debian lesson along: name the function, show the change itself, and treat an answer as a lead until someone can state the reason.

Where the History Misleads

The pickaxe counts exact text. In a copy of the demo where the delay started at 1,000 and a later commit made it 1,100, the search above found only the later commit. A search for await sleep( found the first one. And when a commit only moved the delay to another line of the file, the count did not change, and the pickaxe did not list it. git log -G, which matches the changed lines against a pattern, did.

The pickaxe skips merge commits. The demo has a linear history, in which each pull request landed as one commit. I built a second copy in which the delay arrives the other way. A branch commit with the message “wip” adds it, and a merge commit that carries the pull request’s message brings it in. There, the same pickaxe search returned only the “wip” commit.

Git’s documentation states the rule: unless you ask for the diffs of merges, merge commits will not “match search options like -S.” The exception is --first-parent. At each merge, it follows only the first parent, the branch that received the merge, and by default it compares the merge with that parent:

git log -S "sleep(1100)" \
    --first-parent

With that option, the search returned the merge commit and its message, and it no longer listed the “wip” commit. git blame --first-parent made the same switch for the blamed line. The option leaves out commits that sit only on merged branches, so run the search both ways.

The function form of -L has to recognize your functions. In the demo, lookupAll is a top-level function, and Git found it. When I moved the same loop into a method of a TypeScript class, indented inside the class body, the command failed with fatal: -L parameter 'lookupAll' starting at line 1: no match. A C# method inside a class failed the same way.

Git finds function names the way it labels the hunks of a diff. By default, the gitattributes documentation says, the label is “a line that begins with an alphabet, an underscore or a dollar sign,” and an indented method begins with a space. Git also has built-in patterns for specific languages, but you have to switch them on. One line in a .gitattributes file fixed the C# case:

*.cs diff=csharp

As of Git 2.56, the documented patterns cover C#, Java, Python, Go, and Rust, among others, and none covers JavaScript or TypeScript. For those, give -L a range of lines instead, such as -L 5,12:src/client.ts.

When the History Is Silent

Sometimes the commit says “fix,” the pull request is empty, and nobody remembers. Chesterton’s answer to that reformer is still to go away and think. Software often has an option that a road does not: you can make it safe to find out.

One kind of fence has no reason in the history at all: a behavior that someone downstream came to depend on, such as an odd sort order. Often nobody decided anything, so nobody wrote anything down. That is Hyrum’s Law, and for those fences the place to look is the callers, not the log.

Pin what it does. In Working Effectively with Legacy Code (2004), Michael Feathers calls the tool for this a characterization test: “a test that characterizes the actual behavior of a piece of code.” It records what the code does today, not what it should do. “The tests document the actual current behavior of the system,” he writes. When such a test covers what the fence does and runs before every merge, a removal shows up as a failing test instead of passing unnoticed.

There is a catch, and the delay shows it: a test pins only what it asserts. My first test replaced the vendor module with a stand-in and checked that lookupAll returned what the stand-in returned. Then I deleted the delay, and the test still passed: the stand-in returns the same values however fast the calls arrive.

To pin a delay or a retry, assert on the timing or on the calls. The demo’s sleep wraps setTimeout, which Vitest’s fake timers replace, so this test can take control of the clock and check when each call goes out:

import { afterEach, expect, test, vi } from 'vitest';
import { lookupAll } from './lookup';
import { lookup } from './vendor';

vi.mock('./vendor');

afterEach(() => {
  vi.useRealTimers();
});

test('waits 1,100 ms before each call', async () => {
  vi.useFakeTimers();
  const vendor = vi.mocked(lookup);
  vendor.mockResolvedValue('item');
  const calls = () =>
    vendor.mock.calls.length;
  const tick = (ms: number) =>
    vi.advanceTimersByTimeAsync(ms);

  const ids = ['a', 'b'];
  const done = lookupAll(ids);

  await tick(1099);
  expect(calls()).toBe(0);
  await tick(1);
  expect(calls()).toBe(1);

  await tick(1099);
  expect(calls()).toBe(1);
  await tick(1);
  expect(calls()).toBe(2);

  await done;
});

The test passed against the original file. With the delay deleted, it failed at the first check: two calls had gone out where it expected none. It also failed when I changed the delay to 500 milliseconds and when I changed it to 2,000. One caveat: when I rebuilt sleep on Node’s timers/promises module, the fake timers did not control it, and the test failed with the delay in place.

Make it easy to put back. Take the fence out in its own small pull request, or behind a feature flag, and agree beforehand with whoever watches the logs and alerts what to look for. My articles on the Recoverable Change Principle and feature flags cover the way back in detail.

Weigh the cost. After an honest search, a fence that is cheap to put back can come down as an experiment, through the project’s normal review. Count what happens in between, though. Had the demo’s story been real, deleting the delay to see what happens could have cost a suspended key before anyone noticed.

A security control, a firewall rule, or anything that deletes or rewrites data needs its why first. So does anything that fails quietly. Debian’s weakened generator shipped for about twenty months before the advisory. Cox wrote in a comment under his article that it “would have passed any single-process randomness test I can imagine.”

The search for a reason needs a limit, too. The Chesterton’s Fence entry in my Software Development Principles series warns that the principle becomes pathological when it is used to justify paralysis. It suggests a time limit for the investigation. When the time runs out, defer the high-risk cases above, and proceed with the rest under safeguards that match what you still do not know.

Knowing Why Cuts Both Ways

Finding the reason is not a vote for the fence. Chesterton’s list ends with purposes that “are no longer served.” In code, that verdict has familiar shapes: a workaround for a bug fixed upstream, a check for a client that no longer exists, a limit the vendor has lifted.

If the demo’s vendor lifts its limit, the delay should go, and the commit that removes it should say why. Deleting it then is not reckless; it is the job. My article on the courage to delete code covers how to remove such code safely.

Knowing the reason also lets you build a better fence. A fixed pause in one loop spaces that loop’s calls. It does not coordinate with a second batch that runs at the same time with the same key. Once you know that the rule is one call per second for each key, you can enforce that rule in the one place every caller passes through.

Put Up a Sign

Robert Frost turned the question around in “Mending Wall,” a poem in his 1914 collection North of Boston: “Before I built a wall I’d ask to know / What I was walling in or walling out.” Every fence you build today is someone’s mystery next year, and the reason is cheapest to record on the day you build it. Put the sign where the next person will look:

Michael Nygard described decision records in Documenting Architecture Decisions, and his reason for them reads like Chesterton’s essay. Without the rationale for a past decision, he wrote, a newcomer has “only two choices”: “Blindly accept the decision,” or “Blindly change it.” His remedy is a short text file for each significant decision, kept in the project repository, that records the context, the decision, and its consequences. “It’s better to avoid either blind acceptance or blind reversal.”

For the delay, the sign can sit next to the line itself. A bare 1,100 is a magic number, and the cure is to give the number a name. Here the name comes with its reason:

// Vendor limit: one call per
// second per key. A burst got
// the key suspended for a day
// (#1042). 100 ms is a margin.
const CALL_SPACING_MS = 1100;

The loop then calls sleep(CALL_SPACING_MS), and the test above still passes.

One caution: write down the reason, never the secrets. For a security control, the sign can point to the ticket that holds the reason, where access is already controlled.

A Checklist for Fences

A question to take to your own project: Which fence surprised you most when you found out why it was there?

Further Reading