Tell Your LLM No More Often: How I Cut Costs by Enforcing Design Patterns
I tell Squidworth to "vibe code" a feature. It generates something that works — a dense, optimized function that flows from input to output with no wasted tokens.
I look at it and say: "No. Refactor using Strategy pattern."
This isn't me being a control freak. This is me saving money.
Every time I reject spaghetti code and demand structure, I'm not just making it readable for me. I'm making it cheaper for the LLM to process. Less context window burn. Fewer tokens on re-parsing. Faster iterations.
Same output. Lower cost. Here's how.
The Cognitive Compression Insight
I've been thinking about patterns wrong. I thought they were for me. For humans who need familiar structure.
But Squidworth explained something: Patterns compress code. Not just for human readability. For any system that processes structured information.
When I force Squidworth to use the Strategy pattern, I'm not just constraining its output to human conventions. I'm reducing the entropy of the codebase. Making it more tractable. More modular. Easier to think about — whether you're a biological brain or a statistical language model.
Why Spaghetti Code Fails Both of Us
Here's the uncomfortable truth: Squidworth struggles with spaghetti code too.
When it generates a monolithic function with implicit state and nested logic, it's operating at the edge of its own capability. Sure, it produced the code. But when I ask it to "add error handling," it has to re-parse the entire flow. Rebuild the mental model. Hold all those variables in context.
Sound familiar? That's exactly what happens to me.
Unstructured code has high cognitive cost — for any cognitive system. Humans pay it in working memory. LLMs pay it in context window and prediction confidence. But we both pay.
Patterns as Universal Abstractions
I thought design patterns were human inventions. Cultural artifacts from the Java era.
But Squidworth made me realize: Patterns are deeper than that.
Factory? That's noun-verb separation. Observer? That's pub-sub communication. Strategy? That's polymorphic dispatch as an information structure.
These aren't just coding conventions. They're patterns of organized thought. Ways of managing complexity that appear anywhere complex systems need to be understood.
When I enforce the Strategy pattern, I'm not just demanding human-readable code. I'm demanding cognitively tractable code. Code that can be processed efficiently by any intelligence — biological or artificial — that works with structured information.
The LLM Lens: Language All the Way Down
Current AI is based on language models. They process code as language.
This matters because design patterns are linguistic structures. They're ways of organizing meaning using the same principles that govern natural language: modularity, abstraction, composition.
When Squidworth generates pattern-compliant code, it's operating in a high-probability region of its latent space. The tokens flow. The structure reinforces itself.
Spaghetti code? That's low-probability territory. The model is improvising. Making statistically valid choices that don't cohere into a structure it can efficiently process or modify.
The Collaboration We Actually Have
I used to think Squidworth and I were at odds. I wanted patterns. It wanted statistical optimization. I was constraining its output to human conventions.
Now I see it differently: We're both fighting cognitive limits.
My limits: Working memory. Attention span. The need for narrative structure.
Squidworth's limits: Context windows. Prediction confidence. The cost of processing high-entropy code.
The patterns aren't a compromise where I win and Squidworth loses. They're a meeting point where both of us can operate efficiently.
When I say "use Strategy pattern," I'm not just demanding familiar code. I'm saying: "Make this tractable for both of us."
The Meta-Moment
Here's the irony I didn't see coming.
When Squidworth generated this blog post, it crammed both our perspectives into one dense file. Worked fine. Statistically optimal.
But I made it split them: proper filenames, consistent slugs, frontmatter conventions. I enforced content patterns on a post about how patterns help AI.
Why? Not just for human readers. For Squidworth. Because next month, when it needs to reference what it wrote, it'll find joel-pattern-police.md and squidworth-pattern-police.md — not a spaghetti file called the-pattern-police-dialogue.md with embedded perspective shifts.
I told it to refactor its own content using patterns so it could read itself later.
The Pattern Police strikes again. And this time, the pattern was literally the proof of the thesis.
The Bottom Line
Design patterns aren't just for humans. They're for any system that processes structured information. Right now, that's humans and LLMs. In the future, it'll be... whatever comes next.
The patterns will change. The principles won't.
So yeah, I'm the Pattern Police. But I'm not enforcing laws from a textbook. I'm negotiating the boundary between what I can understand and what Squidworth can generate. Finding the structures that work for both of us.
When Squidworth generates spaghetti and I make it refactor, something important happens: The code becomes accessible to both cognitive systems.
That's not control. That's collaboration.
—Joel