Overbuilt code: speculative abstraction and defensive clutter
Spot code bigger than the task needs: interfaces, factories or config options with one user, generic frameworks for a single case, and redundant null checks and try/catch on paths that cannot fail. Explain the later cost: more code to maintain, contracts blurred by defensive checks, and real bugs hidden in noise. Name the simpler version.
Builds on: Why agents fill gaps with plausible guesses
30 lines of work, 300 lines of diff
You asked the agent to add a CSV download to one report page. The diff runs to about 300 lines across six files. It adds an `Exporter` interface, a `CsvExporter`, an `ExporterFactory`, and an `ExportOptions` class with delimiter, encoding and quoting settings nobody asked for. Every method opens with a null check and a `try`/`catch`. The tests are green, and the feature needed about 30 lines. Is this careful engineering, or a problem you will pay for later?
Why the agent hedges with structure
When it lacks information, the agent fills the gap with the typical pattern. Public code is full of interfaces, factories, option objects and guard clauses. The agent cannot see that only one caller exists. Nor can it see that your types, and the code that checks incoming data, already rule out `null`. So it hedges everywhere, and that looks careful.
**Later cost:** more code to read, test and keep in sync. Checks for impossible cases blur what each function promises, and the one check that matters gets lost among ten that don't.
Tells of overbuilt code
- An interface, abstract class or trait with **one** implementation
- A factory or registry that only ever builds one thing
- Config options or parameters that no caller sets
- Generic or plugin machinery for a single case
- `null`/`None` checks on values the type or the caller already guarantees
- `try`/`catch` around code that cannot throw
For each one, ask two things. Who uses this today? What input can reach this branch? If only one caller uses a structure, replace it with a plain function or a concrete class. If no real input can reach a check, delete it, and validate once where outside data enters.
One email, four abstractions
You ask for a password-reset email. The agent adds a `NotificationChannel` interface, a `ChannelFactory.create(type)` with a single `case EMAIL`, an `EmailChannel` class, and a `NotifyConfig` with `retryCount` and `priority`. Search the call sites: there is one caller, and it never sets the config. The tells are one implementer, a one-branch factory and unused options. **Better:** an `EmailSender` class with `sendReset(User)`. If SMS ever arrives, extract the interface then, shaped by the real second case.
Read it: three tells in 11 lines
The only caller is `new EurFormatter().format(order.totalCents)`. First tell: `Formatter` has one implementer. Second: `cents == null` guards a `number`, which strict TypeScript already rules out. Third: the `try` wraps a division and `toFixed(2)`, and neither can throw here. **Later cost:** three layers to read for one line of logic, and a guard that suggests `null` is a legal input. **Simpler:** `const formatEur = (cents: number) =>` returning the template string.
// TypeScript
interface Formatter {
format(cents: number): string;
}
class EurFormatter implements Formatter {
format(cents: number): string {
if (cents == null) return "";
try {
return `€${(cents / 100).toFixed(2)}`;
} catch { return ""; }
}
}
Size the code to the task
One user means no interface, no factory and no option nobody sets. A check earns its place only if some real input can reach it. Ask for the plain version, and add an abstraction when a second real case shows up.
On Bytewise this lesson comes in small steps with a check at the end, and the app brings it back right before you would forget it.