Monday, 16 November 2026

The problem decides the size of the code, not its shape

For the last few months I've been measuring the shape of code to find god methods: how long a method is, how complex, whether it can be split. Each study found something. Each also ran into the same wall. I now think I had the question the wrong way round. Judging code by its shape, without knowing the problem it solves, is like marking an essay on its length without reading the question. This post explains the change, and why it closes three of my open experiments and merges what was useful in them into one new study.

What I was measuring

Three studies, each a step on from the last:

  • Complexity outliers. Flag the methods and classes whose complexity sticks out from the rest of their codebase (doi:10.5281/zenodo.23581333). It found where complexity piles up. It couldn't tell a god method from a genuinely complex algorithm.
  • Coupling divergence. Weight complexity by how much data a method hands on compared with what it receives. That didn't help. What reviewers actually call a Long Method turned out to be a length: 26 code lines (doi:10.5281/zenodo.23749773).
  • What extraction can't slim. Of the long methods, which ones can't be fixed by extracting methods, and can function injection take them apart (the study, doi:10.5281/zenodo.23991506).

Every one of these looks at code as it stands and asks whether its shape is bad. And every one kept bumping into something an earlier experiment had already shown.

The wall

In the degradation experiments, an AI agent grew the same application through the same 60 change requests, once in Spring and once in OfficeFloor. The result was Conserved amount, negotiable placement (doi:10.5281/zenodo.23190619): the total complexity came out about the same in both. The problem decided how much code there had to be. The framework only changed where it went.

Take that seriously and a problem appears. If the problem decides the amount, then a long, complex method is first of all a sign of a big, complex problem. A measure of how big or complex a method is measures the problem before it measures the code. Across a sample of unrelated projects, you're comparing answers to different questions. At best you find some consistency in the kinds of problems you happened to sample. At worst it's noise.

This gets worse with AI coding assistants. If developers hand assistants bigger and harder problems, what the code assistants write will be bigger and more tangled whether or not it's written well. Comparing its shape with code from before AI would tell you about the problems, not the assistants.

Size versus shape

So I've split two ideas I used to run together:

  • Size is set by the problem. A harder rule needs more code. No framework changes that.
  • Shape is how much room that code has to go where it likes: the space of places it could sit. That's what a framework can change.

The worrying thing isn't that code piles up in one place. Sometimes it should: things that change together are better kept together. That's the old point from Parnas, and it means concentration is neither good nor bad by itself. The worrying thing is code that piles up because it had no choice. A new rule needs a value that only exists inside an existing method, so it has to go inside that method. That method grows. Next time, more of what new code needs is in there, so even more gets pulled in. I've started calling this gravity.

Gravity can be measured, change by change, at the moment the code is written, with the problem held fixed. The next post describes how.

Closing three experiments, merging one

I had several experiments open, and most of them were about to read the same data: the backend Java of the new ui degradation runs, where an agent grows an application through 250 change requests on Spring and OfficeFloor backends. Each was going to measure a shape (junctions, unsplittable methods, sinews) on code where the problem only appears as a growing total. Three registrations would have had to guard against each other reading the same runs. So I've folded them into one study:

ExperimentWhat happens to it
Flow-injection containmentClosed, never registered. Its junction measure becomes one of the shape measures the new study tests. Its "same amount" check becomes the new study's.
SinewSlim analysis planWithdrawn by a dated amendment. It had been pushed to GitHub, which by its own rule registered it, so I couldn't just quietly drop it. Nothing of its runs had been read. Its go/no-go bar for OfficeFloorSlim stays in force, because that's a product decision fixed in advance.
Sinew identificationClosed. A sinew, data riding on the control flow, is what the new study measures as a tie.
Injected-coupling measurementShelved. It only existed to validate a measure for the flow-injection experiment.

Each repository now says so at the top, and keeps its draft as it stood.

Not throwing the old measures away

"Shape without the problem is noise" is a strong claim, and I'm the one who wants it to be true. So the new study doesn't assume it. It tests it. The shape measures from all the earlier studies go in as competitors:

  • is the method long?
  • can it be split?
  • does it hand on more data than it receives?
  • is its complexity an outlier?
  • how lopsided is its class?

The study asks whether any of them still predicts later tangling once the problem and the gravity are held fixed. If one does, then shape carries real information the problem doesn't, and I'll report that.

The study is placement-gravity-study, registered on GitHub (tag plan-v1) before any of the runs it analyses were read. The next post walks through it.

No comments:

Post a Comment