Founder Notes
A Default Case Is a Claim About Strangers
A feed in one of our internal dashboards turns database rows into a list of recent activity. Every row carries an entity type — what kind of counterparty the activity was with — and a small function maps that type onto the label the interface shows.
The function was a switch. It had an arm for several of the kinds we deal with, and at the bottom, a default that returned `vendor`.
So activity with customers and with investors was appearing in the feed as vendor activity. Not as unlabelled, not as unknown: as vendor. A different business object, named confidently, in a view people use to decide who to follow up with.
If you had asked me about that default before I went looking, I would have called it defensive. A fallback. The responsible thing to do with a value you do not recognise, and certainly better than throwing.
It is not a fallback. It is a sentence, and the sentence is: every member of this set that I have not listed here is a vendor.
That is a claim about things I had never seen. It was being made on my behalf, every time the feed rendered, to whoever was reading it.
The part that changed how I write these
Here is what turned a tidy bug into something I have been thinking about since.
A new kind of counterparty was being added to that same enum at the same time, on a different branch. One line in a schema file. Entirely reasonable work, correctly done, by someone with every right to do it.
That one line would have silently changed what the feed asserted about a whole class of rows — in a different file, which that branch did not touch, which nobody reviewing that branch would have had any reason to open. No error. No warning. Not even a conflict, because the two changes do not overlap in a single line of text, so none of our tooling had an opinion about them.
The authority to add a member to a set is cheap and widely held. Anyone who can edit the schema has it, and they should. The authority to decide what a member means to a reader is also cheap, and it lives in whichever function happens to render it.
Those are two different authorities, exercised by different people at different times, with nothing in between them. A set can grow without the code that interprets it ever being told.
The same shape wearing different clothes
Once I had the shape, I noticed I had written the same bug a few weeks earlier somewhere completely different.
I had a check that selected things by name — a handful of keyword patterns, written against everything that existed on the day I wrote them. They were right that day. Later someone added a new item, on a branch, named perfectly sensibly, matching none of my keywords.
My list did not become wrong about anything it named. It quietly narrowed. And a list that has narrowed looks exactly like a list that has not, because the thing that would notice is the thing that is out of date.
Every enumeration is a snapshot of a set on the day it was written. They all decay, and the decay is silent by construction.
What actually fixed it
Not a better default. The default was never really the problem. The problem was that growing the set and interpreting the set had no channel between them.
So we gave the set's growth a way to argue with us: a mapping from every member to a label, with a totality check the type system evaluates. Add a member with no label and the build fails. Growth now has to walk past the code that interprets it.
Two details turned out to matter more than the check.
The first is that extra entries are permitted. The label for the new counterparty kind could be written before the enum member existed. That inverts the usual relationship — instead of the interpreting side permanently lagging behind, it gets to be ready for a member that is not there yet.
The second is that there is still a runtime answer for a value that slips through, and the answer is `unknown`. Which asserts nothing. It is an uglier label and a far better one, because it is the only honest thing that function can say about a value nobody taught it.
The question I had been asking of a fallback was what should I do with a value I do not recognise. The better question is who is allowed to create one, and will I ever hear about it. The answer to the first half is usually "more people than you think." The answer to the second is usually no.
A default case is a claim about strangers. You do not control who joins.