Preemptive Pluralization is (Probably) Not Evil
Tags: reflections, programming, advice
Published: 2021-03-12 23:02:49

---
title: Preemptive Pluralization is (Probably) Not Evil
published: true
description: What if we just assumed we might have two of everything? 
tags: Reflections, Programming, Advice
slug: preemptive-pluralization
canonical_url: https://www.swyx.io/preemptive-pluralization
cover_image: https://i.ytimg.com/vi/INzAc4iI5Zo/maxresdefault.jpg
disclosure: This is an idea I have been mulling for a while, but have not practiced at scale. Written in a couple hours after a prompt from a podcast.
---

*See discussions on [Twitter](https://twitter.com/swyx/status/1370513317379280897), [Reddit](https://www.reddit.com/r/programming/comments/m3wovo/preemptive_pluralization_is_probably_not_evil/),  [Lobste.rs](https://lobste.rs/s/wddhi8/preemptive_pluralization_is_probably), and [my mixtape](https://swyx.transistor.fm/episodes/preemptive-pluralization-is-probably-not-evil)*

**Before you write any code — ask if you could ever possibly want multiple kinds of the thing you are coding.** If yes, just do it. Now, not later.

A few common examples to illustrate:

- You assume that one team has many users, and correspondingly, one user belongs to one team.
    - Eventually, you find that a user may need multiple teams.
    - This is actually fantastic for your business!
    - But you are depressed because you now have to **spend 2 months refactoring every line of code and database schema** that assumed the one-to-one mapping 😱 More examples [here](https://twitter.com/andrewingram/status/1370540227954102274?s=20).
- You assume that loading state only has two states — true / false — so you make a boolean `isLoading` variable
    - Then you realize you need to track error state, so you do, with `isError`. You do some work to make sure the 4 combinations of states behave intuitively. You write tests for each of them like the good developer you are. Of course. 
    - Then you realize you need an `isCanceled` state. 8 and counting...
    - Eventually you realize every addition or modification takes **exponentially longer** to account for each edge case. It's hard to even tell if you've covered them all. Most don't.
    - The solution is [explicit state machines](https://dev.to/davidkpiano/no-disabling-a-button-is-not-app-logic-598i) - but at this point you're too far in to justify a rewrite. 
- **Internationalization**. If you winced at that, you know the pain.
- **Pagination**. To quote [Simon Willison](https://twitter.com/simonw/status/1370542711288209411?s=20), co-creator of Django, "Refactoring an existing non-paginated API to support pagination will break everything. Better to fake pagination but only ever return a single page, just in case".

You can listen to [Ben Orenstein of Tuple discuss this on my mixtape](https://swyx.transistor.fm/episodes/preemptive-pluralization-is-probably-not-evil):

> **I've done this refactoring a million times**. I'll be like, I thought there would only ever be one subscription team, user plan, name, address , and it always ends up being like, "Oh, actually there's more." I almost never go the other way. What if you just paid the upfront cost of thinking "This is just always a collection"?

Donald Knuth is famous for noting that [Premature Optimization is the Root of All Evil](https://www.explainxkcd.com/wiki/index.php/1691:_Optimization#Explanation) (there's [some nuance to that](https://twitter.com/hillelogram/status/1370514421936689154?s=20), btw). I am very sympathetic to the appeal to simplicity — if "You Ain't Gonna Need It", then don't use it. But I think **Preemptive Pluralization** — projecting forward into hypothetical situations when you need N types of a thing — is exempt, even though you are literally optimizing for a future you don't currently live in.

**It is a LOT easier to scale code from a cardinality of 2 to 3 than it is to refactor from a cardinality of 1 to 2.** This is a fundamentally under-appreciated nonlinearity. In other words, Preemptive Pluralization can make the difference between "sure, I'll add that today" and "this is going to take us 2 months and we'll introduce merge conflicts with every other in-progress feature."

## Write Robust Code

[Requirements volatility is a core problem of software engineering](https://stackoverflow.blog/2020/02/20/requirements-volatility-is-the-core-problem-of-software-engineering/). As a software engineer, writing code that does what you ask of it today is the bare minimum. Your real skill comes in what happens next — what you do when requirements inevitably change, whether by new feature request or scaling issues arising from I/O or compute bounds.

It may not be enough to write code for what you foresee in the near term — those are just more requirements. Software design and architecture is all about making it *easy* to respond to *unforeseen* changes.

Hillel Wayne has proposed calling these [requirement perturbations](https://twitter.com/hillelogram/status/1189024161127190528?s=20). If a small, typical feature request can throw your whole design out of whack, then you have **fragile code**. Clearly you want the opposite of fragile — I am tempted to call it "Antifragile" because that gets clicks — but really the best you can hope for is code that mostly doesn't fall apart due to 1-2 standard deviation changes in requirements. In other words: **robust code**. Robust code is [optimized for change](https://twitter.com/swyx/status/1081190319343906816) (more in a future blogpost).

The nonlinearity in how expensive it is to make a change comes from the "[emergent sclerosis](https://twitter.com/david_perell/status/1369534971535298560?s=20)" of code. Code that is robust to future changes is far cheaper to write today, than when written later, as delayed technical debt that you must pay up before you can proceed to a feature request. Fragile code is like the payday loan lender of technical debt.

**Preemptive Pluralization creates Robust Code**.

## Is it Even Premature?

I'm so committed to not prematurely optimizing that I want to make a final pitch for why Preemptive Pluralization is not premature. Let's address two obvious criticisms of Preemptive Pluralization:

- Increased code complexity: Functional languages and other abstractions can help make array or matrix operations almost as easy to work with as regular operations.
- Slow performance from doing extra loops: Loops only cost significantly when you have lots of N. By definition, if you are pluralizing prematurely, N = 1.
- Other concerns raised by readers: [Perf bottlenecks from excessive joins](https://twitter.com/mikesherov/status/1370577582614323201?s=20), [Code Communication](https://twitter.com/mikesherov/status/1370578158194454528?s=20)

Ultimately I think what makes something premature or not is your definition of what you need to write. If you view "code that works today" as your job, preemptive pluralization is premature. If you view "code that doesn't blow up in my face a year from now" as your job, then it is not.

**Make Robust Code a design requirement from the start.**

## More Pluralization Points

More awkward things to pluralize:
 
- Single tenant open source -> Multi tenant hosted service
- Versions -> from no version to v1/v2, or going from "legacy"/"new" to "new new" (hence Stripe [just uses dates](https://stripe.com/blog/api-versioning))
- Number of independently shipping frontends in your company (hence [module federation](https://blog.bitsrc.io/revolutionizing-micro-frontends-with-webpack-5-module-federation-and-bit-99ff81ceb0))
- Number of clouds in your company (you think you will avoid this... until you can't, per [the Hashimoto lemma](https://www.reddit.com/r/devops/comments/91afzz/why_multicloud/))

More from [@nivertech on Twitter](https://twitter.com/nivertech/status/1397069627814027264):

- in-memory→persistent
- single node→cluster
- single language→i18n
- no pagination→pagination
- single user→multi-user
- single tenant→multi-tenant
- single branding→white-labeled
- free→paid
- hard-coded configs→separate config from code
- hard-coded features→feature flags
- online-first→offline-first
- web-first→mobile-first
- no 3rd party API→API-first
- DB-specific→ORM
- local desktop SW→Client/Server
- Client/Server→P2P
- Centralized→Decentralized
- Static→Dynamic
- SSG→SPA

## Related Preemptive Moves

- Timestamps! [you might as well turn your boolean into a timestamp](https://changelog.com/posts/you-might-as-well-timestamp-it). `created_at`, `updated_at`, `deleted_at`. But also `modified_by`, `created_by`, [and more](https://twitter.com/webology/status/1384588570594140160)
- [UUID? Version?](https://twitter.com/MichaelDrogalis/status/1391454881068720131) - don't use the UUID as a PK.

## Acknowledgements

- *Thanks to [Jon Wong](https://twitter.com/jnwng/status/1370524452480454665?s=20) for reviewing a draft of this post and contributing the boolean and internationalization examples*
- *Endorsements & Horror stories from [Simon Willison](https://twitter.com/simonw/status/1370541425465520130?s=20), [Ben Orenstein](https://twitter.com/r00k/status/1370520023995985922?s=20), [Andrew Culver](https://twitter.com/andrewculver/status/1370527597885599746?s=20), [Andrew Ingram](https://twitter.com/andrewingram/status/1370540227954102274), [Tanner Linsley](https://twitter.com/tannerlinsley/status/1370567716935888897?s=20), [Ryan Murphy](https://twitter.com/rdmurphy/status/1370544608896192513?s=20), [David Welch](https://twitter.com/david_welch/status/1370916290584403971) and [Khrome](https://twitter.com/KhromeDotDev/status/1370544511408033794?s=20)!*
- Daniel Buckmaster compares this idea to [Sandi Metz's POODR](https://dev.to/crabmusket/comment/1cc36).
- [Martin Gronlund](https://dev.to/martingronlund/comment/1ccce) compares this to [data oriented design](https://www.youtube.com/watch?v=rX0ItVEVjHc).
- [Jared Palmer](https://twitter.com/jaredpalmer/status/1370529091804364801?s=20) and [Daniel Yokomizo](https://twitter.com/dyokomizo/status/1370598973036199936?s=20) mention the [Zero one infinity rule](https://en.wikipedia.org/wiki/Zero_one_infinity_rule) - though this article argues FOR preemptively favoring "infinity" over "one"