The Problem with 'Clean Code' Dogma
"Clean Code" is a fantastic book. Its principles have guided a generation of developers out of the dark ages of 5,000-line god-classes and variable names like x1 and dataArray.
But recently, I've noticed a troubling trend: the transformation of these helpful guidelines into rigid, unyielding dogma.
When developers prioritize the appearance of clean code over the reality of readable code, we end up with systems that are beautifully architected but impossible to understand.
The Fragmented Function
One of the core tenets of Clean Code is that functions should be small. "Functions should do one thing. They should do it well. They should do it only."
In theory, this is great. In practice, I often see it taken to an extreme. A straightforward 40-line procedural function that reads top-to-bottom gets shredded into eight 5-line functions spread across three different files.
Suddenly, understanding the business logic requires you to maintain a mental stack trace, jumping back and forth between files just to figure out how a user gets authenticated.
Code readability is about context. Sometimes, seeing the whole process in one place (even if it's 50 lines long) is significantly clearer than chasing a trail of meticulously abstracted one-liners.
The Naming Obsession
"Choose descriptive and unambiguous names." Again, great advice. But I've reviewed PRs where developers spent 45 minutes debating whether a variable should be userList, arrayOfUsers, activeUsersCollection, or hydratedUserModels.
If the scope of the variable is only 5 lines long, users is fine. Sometimes, within a highly constrained mathematical formula, even i or x is acceptable. The broader the scope, the more descriptive the name needs to be. Context matters.
The Abstract-Early Anti-Pattern
The worst offense of Clean Code dogma is premature abstraction.
The DRY (Don't Repeat Yourself) principle is drummed into our heads from day one. As soon as a developer sees the same three lines of code in two places, they feel compelled to extract it into a shared utility function.
But what if those two places are doing things that only happen to be identical right now, but will inevitably diverge in the future?
By tying them together prematurely, you couple two unrelated parts of the system. When one needs to change, the shared utility becomes a convoluted mess of boolean flags and conditional logic.
As Sandi Metz famously said: "Duplication is far cheaper than the wrong abstraction."
Pragmatism > Perfection
Code is not art meant to be hung in a museum. It is a tool meant to solve problems.
The goal of "clean" code shouldn't be to satisfy a linter or adhere to a checklist in a 15-year-old book. The goal is to ensure that the next person who opens the file (which will probably be you in six months) can understand what it does and change it safely.
Sometimes that means writing a 60-line function. Sometimes it means repeating yourself. And that's okay.