Every project eventually hits the natural limits of its architecture—you hit some problem that just doesn’t fit the way things work. Maybe you need to add a feature that can’t be expressed in your paradigm. Say you’ve got a filtering mechanism that lets you specify a set of criteria that all need to be met, and you run into a case where you need to OR some criteria instead of AND ing them.

Or the shape of the data has changed. You built the system to solve problems of some size, and over time it starts to be applied to problems of a different size or shape, and you’re running into existential performance problems.

It could be that things are just getting tangled. Your paradigm provides ways to tweak the core behavior of the system in special cases, which is one of the reasons it’s lasted as long as it has. But now the extension mechanism is used in every single case , not just special ones. Every use of the system is a hopscotch through different exceptional cases, and it’s hard for people to figure out whether something new works, much less how it works.

Maybe some bit of code is old enough that it just doesn’t fit with the rest of your codebase. You’ve got a bit of C code in your fairly forward-thinking C++ project, and you recoil at all of its hand-rolled pointer structures. It represents an older, alien way of thinking, and everyone wants to rewrite it in a more modern paradigm.

This sort of thing is natural and inevitable, and shouldn’t cause you to panic. It’s not even really a problem. It’s just how things go.

If you think you can forestall this—that hitting the natural limits of your architecture is a sign of poor initial design, and that a better design would have avoided the problem—then remember the example of Rule 4 , that generalization takes three examples. Your initial design may well have been poor. But the most likely result of trying to predict the future would have been a similarly poor but more complicated design that would have hit its limits even earlier.

You won’t hit architectural limits on every single part of your project, either. Some parts will happily tick along for years without any rework. That’s not an accident—if you make good choices in your initial design, the problems you’re solving stay pretty much the same, you and your teammates are diligent about keeping things tidy, and whatever exceptional cases you run into are localized and easily handled, then things can trundle along with no changes indefinitely.

That’s why futureproofing is so dangerous. Some of the time it’s not necessary, and the rest of the time it doesn’t work.

Three Paths Forward: Ignore, Tweak, or Refactor

Anyhow , you’ve run into a natural limit of some sort. That doesn’t mean you’re forced to tear up the code and start again from scratch.

You could just live with the natural limit, for instance. Don’t allow OR clauses in your filtering, or buy bigger hardware to deal with your performance problems, or live with some extra complexity and old-fashioned code.

Small tweaks and exceptional cases might also work. Maybe your filtering is really an AND -of- OR s, like most websites, and you can handle the one extra OR in your special case by combining two categories in your UI. Maybe most of your performance issue springs from recalculating some bit of data, and a little bit of caching will mostly fix the problem. Maybe every use of the system runs through the exceptional mechanism, but most of those exceptions are all the same thing, and you can just fold that case into your core code path and get rid of a bunch of exceptional cases. Maybe the only really old-fashioned thing is the use of a set of half-baked macro-driven functions to deal with allocating C arrays, and it’s not too hard to just convert them to std::vector .

Or maybe you really do need to make some major changes. Your architecture was designed to address the problem as you understood it when work started. The problem has changed, though—or maybe your understanding of the problem is deeper now. Your current architecture just can’t solve the problem as you now understand it, and you see a better approach.

So how do you decide which of these three basic approaches to take? Do you ignore the issue, tweak things to address it, or do a bigger refactoring?

Gradual Evolution Versus Continual Reinvention

There’s a natural tendency in programmers to handle this question poorly—to make big changes for the wrong reason at the wrong time and end up causing more problems than they solve.

More specifically, there are two subspecies of programmers. Type One programmers think incrementally. They look at each new problem in terms of the existing solution; they always solve problems by tweaking the current design. Type Two programmers think of the problem and solution together; they’re attracted to fixing all the issues with a system, not just the issue at hand, and jump at the chance to start over with a new design.

Either tendency taken to extremes is a disaster. If all fixes are incremental, you end up trapped, pushing off requests for improvements to the project, slowly buried under the weight of years of tweaks and exceptional cases. If no fixes are incremental, if all changes are ground-up reworks, then you thrash in place. You’re continually throwing out the things you’ve learned about the last architecture. Every new architecture brings a new set of problems and you never make progress.

As in most things, the best results come from striking a balance. Choosing the right approach—ignore, tweak, or refactor—can be tricky, but knowing your tendencies and the tendencies of your coworkers can help you make better decisions. If your response to uncertainty is to make the decision that is comfortable for you, then you risk choosing the same alternative every time. If you’re a Type One programmer, the comfortable decision is incremental, and all problems are solved by tweaking or ignoring. If you’re a Type Two programmer, the comfortable decision is to rework everything, so that’s what happens every time. That’s not good; you need to balance the two.

Some red flags that Type One thinking might be getting out of control:

  • Describing the issue at hand in terms of the current architecture. That might be as simple as using internal terms instead of describing the issue in its own problem space. Sometimes it’s hard for Type One coders to even think about the problem except in terms of the existing architecture, and this shows up in the language they use.

  • Using words like impossible to describe the issue. That’s almost certainly not true—at worst, the issue is difficult to solve without major changes to the system architecture.

  • Deploying the project schedule as a conversation-stopper. This is not to imply that schedule concerns aren’t valid—they obviously are! But if the first and only argument you make against a big change is that it won’t fit in the schedule, then you might be stuck in Type One thinking.

  • It’s been years since the last major change was made to the system, despite many incremental changes to it.

Some warning signs that Type Two thinking is taking over:

  • The best reason you’ve got for reworking the system is “we really need to clean up that bit of code.”

  • The decision to rework a system is driven by one particular case, like a single feature that’s hard to implement, or a dataset that creates poor performance.

  • The argument for reworking things is driven by performance or resource issues, but nobody has actually profiled the system to find the bottleneck.

  • You present arguments for reworking the system in terms of the solution, not the issue at hand. Any proposals that aren’t grounded in the problem are pretty suspect.

  • Some bright, shiny object—a new language, a new library, some new language construct—is central to the proposed reworking.

You might have recognized some of your own thought patterns in there! I certainly do—I’m Type Two at heart and have to keep that mind when I’m making decisions. Luckily there are lots of Type Ones on my team who I can rely on to provide some decision-making balance.

It’s also common to get mixed signals, with Type One and Type Two warning signs popping up for the same problem. For example, maybe you’re considering a big change for a system that hasn’t seen fundamental rework for years, but the impetus for the suggested change appears to be excitement about deploying a cool new database technology. That’s a Type One signal (the system’s architecture has been static for a long time) and a Type Two signal (Squee! A new database!) mixed together.

Recognizing these patterns can help your decision-making process, but they won’t make the decision for you. You might see some conservative Type One patterns in your logic, but that doesn’t mean an incremental solution is wrong! Nor does the presence of Type Two signals mean that reworking your system is inappropriate. You need something more to help you make the big decision about whether to embark on major rework or keep making incremental changes .

A Simple Rule of Thumb

Here’s my simple rule of thumb for making a big change: is it twice as good?

If you’re confident that after your changes, the reworked system will be twice as good as the system you’ve got now, then the reward is big enough to justify the disruption and the new problems that the rework will inevitably introduce. If not—if the new system isn’t going to be twice as good as the current one—then it’s better to address the issue incrementally.

Sometimes the answer is obvious. You absolutely need to do something, and your current architecture absolutely can’t do it. Say you need to rework your server code to support new legally mandated privacy restrictions. Those restrictions require a “right to be forgotten,” implying functionality that your current architecture fundamentally can’t support because it intermixes data histories in a way that precludes removing an individual’s old data.

Will a new system be twice as good? In this case, you need to do something that the reworked system will support and the current system can’t support. In some sense, the reworked system is infinitely better than the old one. Since “infinitely” is comfortably larger than “twice,” the decision is clear, and you set forth on your rework.

More commonly the answer isn’t as obvious, and you need to do some measurement (if possible) and estimation (if measurement isn’t possible) to decide whether the new answer is twice as good as the old one.

For instance, when Sucker Punch started work on Ghost of Tsushima , we realized that the way we physically modeled the ground was going to struggle with the size of the new game. Our previous games had all represented the ground as a surface composed of hand-built triangles, but the new game covered 40 or so times as much ground. The actual ground of the island of Tsushima was created using a collection of height maps, each a 512 × 512 bitmap representing a uniform grid of heights covering a 200-meter square.

The incremental solution was to convert the height maps to triangles and feed them through our normal physics pipeline. This worked fine, but it was really bulky—there were half a million triangles, and even after some light optimization we were spending many megabytes of storage keeping track of all of them.

We had an alternative—we could rework the physics engine to support height maps directly, but this implied a lot of work. It meant handling the height maps’ interaction with all of the other basic physics primitive types, figuring out how to encode the extra information our physics engine needed about surface types into the height map, adding height map support to all of our debugging tools, and so on. Getting everything working would end up taking about three programmer-months of work.

Applying the rule of thumb, then—would the reworked system be twice as good? On a few axes, absolutely! We already had the height maps for use by our rendering engine, and we could infer everything else we needed. Instead of the 20+ megabytes we’d needed to physically model each 200-meter-by-200-meter square of the game, we would need only a few hundred bytes to integrate a height map. 1

Similarly, basic physics operations (like testing a short line segment) only needed to query a cell or two in the height map, instead of hopping through dozens of layers of the binary spatial partitioning tree we use to represent more free-form geometry. This would be much more than twice as fast.

So, the rule of thumb said that this rework made sense—the new system would be twice as good on important metrics, and we decided this would be worth the cost of implementing and dealing with the revised workflows and new bugs .

Dealing with Fuzzy Benefits

It’s not always easy to quantify the benefits of reworking stuff, but that’s not a good excuse for side-stepping the “twice as good” rule. If you’re focused on soft improvements—like a change that will make your programmers happier, or a rebuilt authoring pipeline that will let your designers create slicker UX—then figure out how to quantify them.

If you don’t, you’re setting yourself up to make the most comfortable decision—the one that fits your natural tendency. If you make the comfortable decision too often, you’ll get yourself in trouble.

Let’s say the goal of some change is merely to make the programmers on the team happier, like the earlier example of replacing some old-fashioned code. So why will your programmers be happier? Will they be more productive because they’re not struggling with the bugs that reliably pop from the current tangled mess? If so, how much more productive? Twice as productive?

Or let’s say you’re deciding whether to rebuild your UX authoring pipeline. How much slicker will the new UX be? Why and how will it be better for your product’s users, and how can you predict that improvement? Will users spend more time enjoying your product, which is what we aim for with games? Or, if you work on more traditional software, will your users be able to get their tasks done more quickly and effectively?

Rework Is a Good Opportunity to Fix Small Problems

One last thought before we get back to a chapter with actual source code.

Once you’ve decided to rework a system, you might as well tidy up all the little things that are wrong with it. You wouldn’t embark on major rework just to fix some bit of old-fashioned code—the benefit isn’t worth the problems you’d introduce. But if you’ve already decided to tear up that bit of code, you’re already going to absorb the cost of changing things, and you’re going to be testing your changes thoroughly anyhow—so you might as well solve some smaller problems along the way, like replacing that bit with more modern code.

This is a pretty productive pattern. Note the little problems in your code that you can’t fix right away. Then, when you’re doing major work in an area, sweep up all those little problems at the same time.

That doesn’t say you shouldn’t look for incremental improvements. Use incremental changes to make those improvements. Maybe, over time, you’ll collect enough small ideas about ways the system could improve that you can justify major rework. That’s pretty common, actually, especially if you start to see patterns. If you see a half-dozen small issues with the current system that could all be addressed by the same bit of rework, then maybe you’ve found the tipping point where the cumulative value makes the rework worth the effort. Collectively, the improvement would be major and justifies major rework .

“Twice as good” is a convenient way to say that major changes require major improvements. Don’t tear up something to replace it with something marginally better; that’s a bad strategy. Tear something up to replace it with something much better. Twice as good.

1 For a complex set of reasons, we eventually ended up making a separate copy of the height map used by rendering, then converting it to floating point as part of the copy, at a total cost of about 1 megabyte for each 200-meter-by-200-meter square.