Rough Work/the craft

Wait for the Pattern

The instinct kicks in the second time you write similar code. This should be a shared function. DRY—Don't Repeat Yourself. Extract it now, before it spreads.

The problem is that two examples aren't enough to know what the abstraction should actually be. You're looking at a sample size of two, inferring a pattern that doesn't fully exist yet. The shared function you write captures what the code looks like today, not what it needs to become.

A useful heuristic: wait for three. Let the code repeat a second time, then a third. By the third instance, the real shape of the problem starts to emerge. Each copy that lives in production gets shaped by reality—edge cases, requirement changes, different callers with different needs. That pressure reveals what varies and what stays the same. The abstraction you write after three real examples is built on evidence, not intuition.

This requires resisting a reflex that feels virtuous. Duplication looks like a mistake. But premature abstraction has a higher cost—it's just a harder one to see. The duplication is visible and local. The wrong abstraction hides its damage across every file that depends on it.

You can always abstract later. You can't easily un-abstract.

to navigate