How AI Changed the Economics of Writing Clean Code

- AI 降低了编写代码的成本,但阅读代码的认知负担仍是瓶颈。
- 接口和抽象设计通过减少认知负载提升代码可读性和维护性。
- 现代软件开发应更关注语义层面的理解而非底层实现细节。

If you've ever wanted to add an interface to a codebase and gotten pushback, you already know the argument: "That's twice the code for the same thing."
And honestly? It was a fair point. You'd write the contract — the interface, the abstract class, the protocol — and then write the implementation. Two files where one would do. That's more surface area, more indirection, and more to maintain.
The Ruby and Rails communities built an entire philosophy around this: convention over configuration, less ceremony, fewer keystrokes. If the framework could infer your intent, why spell it out?
Then AI happened.
I was recently chatting with a CEO about what current-generation software engineers get wrong, and he put it cleanly:
"Abstract interfaces were challenging a few months ago just because it required twice as much code. But with AI, lines of code are free. The reason we still need such constructs is because at some point a human still needs to look at the code. Interfaces reduce the cognitive load."
That framing stuck with me. The cost of writing code has collapsed. The cost of reading it hasn't moved. And that asymmetry changes everything about how you should think about abstraction.
Here's what I mean.
Table of Contents
Your Brain Is the Bottleneck
This isn't a vibes argument. There's actual neuroscience behind why interfaces help.
In 1988, educational psychologist John Sweller introduced Cognitive Load Theory. A 2022 ACM review covers how it's been applied to computing education since.
The short version: your brain juggles three types of load when processing information. _Intrinsic_ load is the inherent difficulty of the problem itself. _Extraneous_ load is the noise — poorly organized information, unnecessary details, bad naming. _Germane_ load is the good stuff — the mental effort you spend building useful mental models.
Here's the kicker: your working memory can only hold a handful of chunks of information at a time — cognitive scientists typically estimate somewhere between 2 and 6. Not 2 to 6 files, or 2 to 6 classes — 2 to 6 _things_.
Felienne Hermans explores this in _The Programmer's Brain_ (2021), arguing that design patterns act as chunking aids. When you recognize a Strategy pattern, your brain collapses an entire class hierarchy into a single cognitive unit. The word "Strategy" replaces five classes and their relationships. That's not hand-waving about clean code — that's how human memory actually works.
And we can literally see it on brain scans. In 2021, a team led by Norman Peitek and Janet Siegmund published an fMRI study on program comprehension that won the ACM SIGSOFT Distinguished Paper Award at ICSE.
They put developers in brain scanners and watched what happened when they read code. The finding: semantic-level comprehension — understanding _what_ code does — required measurably less neural activation than bottom-up syntactic parsing — tracing _how_ it does it.
An interface lets you comprehend at the semantic level. `UserRepository.findById(id)` tells you everything you need to know without opening the implementation. Your brain doesn't need to hold the SQL query, the connection pool logic, the error handling, and the result mapping in working memory simultaneously. The interface compresses all of that into one chunk.
That's not elegance. That's neuroscience.
The Greats Already Knew This
The case for abstraction isn't new. The people who built the foundations of computer science were making this argument before most of us were born.
Dijkstra said it with precision:
_"The purpose of abstracting is not to be vague, but to create a new semantic level in which one can be absolutely precise."_
Abstraction isn't about hiding things from people who can't handle complexity. It's about creating a level of discourse where you can reason clearly.
David Parnas formalized information hiding in his 1972 ACM paper: _"Every module is characterized by its knowledge of a design decision which it hides from all others."_ He proved that decomposing systems by design decisions (rather than processing steps) produced modules that were both more flexible _and_ easier to understand. Comprehensibility wasn't a bonus — it was the design criterion.
Tony Hoare argued that abstraction is the most powerful tool available to the human intellect — a way to manage complexity by focusing on what matters and ignoring what doesn't. Martin Fowler brought it down to earth:
_"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."_
And then there's John Ousterhout, whose book _A Philosophy of Software Design_ (2018) makes the connection to cognitive load explicit. His central argument: more lines of code can actually be _simpler_ if they reduce cognitive load.
His concept of _deep modules_ — simple interfaces hiding complex implementations — is essentially the argument that interfaces are worth their weight in code. The Unix file system API (`open`, `close`, `read`, `write`, `lseek`) is five functions hiding an enormous amount of complexity. That's a deep module. That's the goal.
The Gang of Four put it first in their book for a reason. Page one: _"Program to an interface, not an implementation."_
None of this is controversial. But it's easy to forget when your AI tool just generated 200 lines of perfectly functional inline code in three seconds.
The Economics Have Flipped
Here's where the CEO's insight becomes an economic argument.
The historical case against interfaces was always about _writing cost_. Interfaces meant more code to write, more files to create, more boilerplate to maintain. The entire dynamic typing movement — Python, Ruby, JavaScript — was partly a reaction to the ceremony that languages like Java imposed. Convention over configuration. Don't Repeat Yourself. Less is more.
But ask yourself: what exactly is the cost of writing boilerplate now?
GitHub's 2022 controlled study found that developers using Copilot completed tasks 55% faster. The boilerplate that used to justify skipping interfaces — the extra file, the type definitions, the method signatures — takes seconds to generate. The writing cost of an interface has effectively collapsed to zero.
But again, the reading cost hasn't budged.
Robert C. Martin argued in _Clean Code_ (2008) that developers spend far more time reading code than writing it — an observation he framed as a ratio of 10 to 1.
You can quibble with the exact number (it's anecdotal), but the direction is consistent across studies. A large-scale field study tracking 78 professional developers across 3,148 working hours found they spend roughly 58% of their time on program comprehension alone. New developer onboarding averages six weeks — most of which is spent understanding existing systems, not producing new ones.
Addy Osmani named this asymmetry perfectly. In a March 2026 piece, he described _comprehension debt_:
"When a developer on your team writes code, the human review process has always been a bottleneck — but a productive and educational one. Reading their PR forces comprehension. AI-generated code breaks that feedback loop. The volume is too high."
The output looks clean, passes linting, follows conventions — precisely the signals that historically triggered merge confidence. But comprehension debt is distinct from technical debt because it accumulates invisibly — your velocity metrics, your DORA scores, your PR counts all look fine while your team's actual understanding of the codebase quietly erodes.
So here's the math: AI reduced the cost of writing abstractions to near zero. The cost of _not_ having them — in human reading time, onboarding friction, and comprehension debt — hasn't changed at all. The break-even point for "is this interface worth it?" just shifted massively in favor of "yes."
The Data Backs It Up
This isn't theoretical. We have data on what happens when AI generates code without good abstractions.
GitClear analyzed 211 million changed lines of code between 2020 and 2024. Their findings: code churn — lines reverted or updated within two weeks — doubled compared to the pre-AI baseline. Copy-pasted code blocks rose from 8.3% to 12.3%. And refactoring-associated changes dropped from 25% to under 10%.
AI-generated code, as they put it, "resembles an itinerant contributor, prone to violate the DRY-ness of the repos visited."
The METR study (2025) found something even more striking. Experienced open-source developers _predicted_ AI would make them 24% faster. They _perceived_ being 20% faster while using it. They were actually 19% slower. The perception gap is the story — you _feel_ productive while generating code that creates more work downstream.
And then there's a study from Anthropic (yes, the company that makes Claude — full disclosure). They observed 52 software engineers learning a new library. The AI-assisted group completed tasks at the same speed, but scored 17% lower on comprehension quizzes afterward — 50% versus 67%. The biggest declines were in debugging ability. You can ship code you don't understand. You can't debug code you don't understand.
Kent Beck put it bluntly: "The value of 90% of my skills just dropped to $0. The leverage for the remaining 10% went up 1000x." What that remaining 10% is, he leaves deliberately open — but it's hard to read that and not think about system design.
The Contrarian Case (And Why It Actually Agrees)
I'd be dishonest if I didn't address the people who argue against abstraction. And some of them are very smart.
Casey Muratori's "Clean Code, Horrible Performance" demonstrated that polymorphism and virtual dispatch can make code 10 to 15 times slower than straightforward procedural alternatives.
His benchmark is real. If you're writing a game engine or a high-frequency trading system, abstract interfaces on your hot path will cost you.
Dan Abramov wrote "Goodbye, Clean Code" after watching a premature abstraction make his codebase harder to modify:
_"My code traded the ability to change requirements for reduced duplication, and it was not a good trade."_
Sandi Metz put it more sharply: _"Duplication is far cheaper than the wrong abstraction."_
And Rich Hickey, in his talk "Simple Made Easy", draws the critical distinction: _simple_ (not intertwined) is not the same as _easy_ (familiar). Wrong abstractions _complect_ — they braid concerns together rather than separating them.
Here's the thing: none of these are arguments against abstraction. They're arguments against _bad_ abstraction.
Muratori's performance argument applies to hot paths in performance-critical systems — not to your REST API's service layer. Abramov and Metz argue against _premature_ abstraction — pulling patterns out before you understand the domain. And Hickey's entire talk is a case _for_ the right abstractions, the ones that genuinely decompose rather than complect.
The irony is that in an AI-assisted world, these arguments are _easier_ to address. You can generate the explicit, unabstracted version first. Let it stabilize. Watch the patterns emerge. Then extract the abstraction — with AI handling the mechanical refactoring. The cost of the "duplicate first, abstract later" approach just dropped to near zero.
What This Means for You
If you're writing code with AI tools — and at this point, most of us are — the temptation is to let the AI produce whatever it produces and move on. It works. It passes the tests. Ship it.
But "it works" is table stakes. The harder question is: can the next person who opens this code understand it in under five minutes? Can _you_ understand it in six months?
Interfaces aren't about making code prettier or satisfying some abstract (pun intended) design principle. They're compression algorithms for human cognition. They let your brain operate at the semantic level instead of the syntactic level. And now that AI has eliminated the only real cost of creating them — the boilerplate — there's no economic argument left for skipping them.
The rules haven't changed. The excuse has just expired.
References
Academic Papers
- Duran, R., Zavgorodniaia, A., & Sorva, J. (2022). "Cognitive Load Theory in Computing Education Research: A Review."_ACM Transactions on Computing Education, 22_(4), Article 40.
- Parnas, D.L. (1972). "On the Criteria To Be Used in Decomposing Systems into Modules."_Communications of the ACM, 15_(12), 1053–1058.
- Peitek, N., Apel, S., Parnin, C., Brechmann, A., & Siegmund, J. (2021). "Program Comprehension and Code Complexity Metrics: An fMRI Study."_ICSE 2021_. ACM SIGSOFT Distinguished Paper Award.
- Peng, S., Kalliamvakou, E., Cihon, P., & Demirer, M. (2023). "The Impact of AI on Developer Productivity: Evidence from GitHub Copilot."_arXiv:2302.06590_.
- Shen, J.H. & Tamkin, A. (2026). "How AI Impacts Skill Formation."_arXiv:2601.20245_.
- Xia, X., Bao, L., Lo, D., Xing, Z., Hassan, A.E., & Li, S. (2018). "Measuring Program Comprehension: A Large-Scale Field Study with Professionals."_IEEE Transactions on Software Engineering, 44_(10), 951–976.
- METR. (2025). "Measuring the Impact of Early 2025 AI on Experienced Open Source Developer Productivity."_metr.org_.
Talks and Blog Posts
- Hickey, R. (2011). "Simple Made Easy."_Strange Loop Conference_.
- Beck, K. (2023). "90% of My Skills Are Now Worth $0."_Tidy First? Substack_.
- Osmani, A. (2026). "Comprehension Debt: The Hidden Cost of AI-Generated Code."_addyosmani.com_.
- Muratori, C. (2023). "Clean Code, Horrible Performance."_Computer Enhance_.
- Abramov, D. (2020). "Goodbye, Clean Code."_overreacted.io_.
- Metz, S. (2016). "The Wrong Abstraction."_sandimetz.com_.
- GitClear. (2025). "AI Assistant Code Quality in 2025."_gitclear.com_.
- * *
- * *
Learn to code for free. freeCodeCamp's open source curriculum has helped more than 40,000 people get jobs as developers. Get started