DEV Community

Cover image for The Cult of Clean Code
Adam - The Developer
Adam - The Developer

Posted on

The Cult of Clean Code

A few days ago, I watched a senior developer spend 3 days refactoring a perfectly functional feature because the functions were "too long." The code worked. Users were happy. Tests were green. But somewhere, Robert C. Martin's ghost was apparently crying, so we had to fix it.

Spoiler alert: the refactored version introduced two bugs and made the codebase harder to understand. But hey, at least the functions were under 10 lines each, right?

The Clean Code Kool Aid

I get it. When you're drowning in legacy spaghetti code at your first job, Clean Code feels like a life raft. Uncle Bob shows up with his commandments ("functions should do one thing," "no comments," "DRY everything") and suddenly you have RULES. Structure. A way to feel superior in code reviews.

  • "Actually, this function violates SRP."
  • "This comment is a code smell."
  • "We should extract this into our own class."

Congratulations, you're now part of the problem.

Clean Code isn't a book about programming. It's a book about programming religion. And like all religions, it offers simple answers to complex questions, eternal truths in a chaotic universe, and a convenient way to divide the world into the righteous and the sinners.

The Abstraction Trap Is Real and It's Killing Your Velocity

Here's what they don't tell you: DRY is a trap.

That's right, I said it. Don't Repeat Yourself has probably caused more damage to codebases than copy and paste ever did. Because here's what happens in practice:

You see two functions that look similar. Clean Code sirens start blaring in your head. You extract a common abstraction. You add parameters to handle the slight differences. Then more parameters. Then a config object. Then a strategy pattern because you're a Real Engineer™.

Six months later, someone needs to modify one of those original use cases. But now they can't just change the code. They have to understand your beautiful abstraction, figure out which of the seventeen parameters to modify, hope they don't break the other use cases, and pray the unit tests actually cover the edge cases.

Duplication is far cheaper than the wrong abstraction. This isn't even controversial. Sandi Metz said it years ago. But Clean Code zealots keep building their elaborate houses of cards because Uncle Bob told them to.

Small Functions Are Not Automatically Better

"Functions should be 4 to 5 lines long," says Uncle Bob.

Cool. Let me just split this perfectly readable 30 line function into six tiny functions with adorable names like validateUserInputAndReturnProcessedData() that you now have to jump between to understand what's actually happening.

You know what's easier to understand than six 5 line functions? One 30 line function that does ONE THING from start to finish. I can read it top to bottom. I don't need an IDE with "go to definition" just to follow the logic. It's right there.

But no, we have to make everything "clean" by fragmenting logic into microscopic pieces and pretending that extractUserData() calling validateUserData() calling processUserData() calling saveUserData() is somehow more maintainable than just doing those things in sequence.

Comments Aren't Evil, Your Codebase Is Just Boring

"Good code doesn't need comments" is the most cargo cult nonsense in the entire Clean Code canon.

Sure, getUserById(id) doesn't need a comment explaining that it gets a user by ID. No kidding.

But you know what DOES need a comment? The gnarly bit of code that works around a weird API quirk. The regex that took you 2 hours to write. The business rule that doesn't make sense until you know about the compliance requirement from 2019. The performance optimization that looks weird but saves 200ms per request.

Your code can explain WHAT it does. It cannot explain WHY you did it that way. That's what comments are for.

Every time someone removes an "obvious" comment, they're basically saying "I understand this right now, so everyone will understand it forever." That's not confidence, that's hubris.

Uncle Bob Built a Brand, Not a Methodology

Let's talk about the elephant in the room: Robert C. Martin is a businessman first and a thought leader second.

He's got books to sell. Conference talks to give. Consulting gigs to book. Training courses to market. The entire Clean Code industrial complex is his brand, and that brand is worth a lot of money.

I'm not saying his advice is wrong because he profits from it. I'm saying we should maybe be a LITTLE skeptical when someone builds their entire career around being the authority on One True Way to write code.

Real talk: Uncle Bob hasn't written production code at scale in decades. He's not dealing with your microservices architecture, your NoSQL databases, your React state management, your Kubernetes configs. He's writing Java examples in books and telling you how to be a "professional."

And yet we treat his 15 year old opinions like they're carved in stone.

The Real Problem: Pattern Matching Over Thinking

Here's what actually happens when Clean Code becomes dogma:

Junior devs learn the rules. They apply them everywhere. They pattern match "long function equals bad" and "duplication equals bad" and "comments equal bad" without engaging their actual brains.

Code reviews turn into rule enforcement instead of knowledge sharing. "This violates SRP" becomes a thought terminating cliche. Nobody asks "is this actually a problem?" or "does this abstraction make sense?" They just enforce The Rules.

And god forbid you ship code that works but doesn't follow the checklist. You're not a Real Programmer™ yet. You need to read more Martin Fowler. Maybe take Uncle Bob's course.

What Actually Matters

You want to know what makes good code? Here's the secret that won't make me any money:

Good code solves the problem correctly and can be modified by your team without making them want to quit.

That's it. That's the whole thing.

Sometimes that means small functions. Sometimes that means one big function. Sometimes that means duplication. Sometimes that means abstraction. Sometimes that means comments everywhere. Sometimes that means self documenting code.

It depends on your team, your domain, your constraints, and your timeline.

The developers I respect most aren't the ones who can recite SOLID principles in their sleep. They're the ones who can look at a problem and make pragmatic trade offs. They can write clever abstractions when they're worth it and boring straightforward code when it's not. They know when to refactor and when to ship.

They think instead of pattern matching.

Breaking Free

If you're reading this and feeling attacked, good. That discomfort means you're thinking critically, maybe for the first time in a while.

Try this: next time you're about to refactor working code because it "violates a principle," stop and ask yourself:

  • Is this causing actual problems right now?
  • Will this refactoring make the code easier to change in ways we actually need to change it?
  • Am I doing this because it matters or because I read it in a book?

And if someone tells you your code isn't "clean enough," ask them what problems it's causing. Not theoretical problems. Actual problems. If they can't articulate any, maybe it's fine the way it is.

Let's Be Clear: Refactoring Isn't the Enemy

Before someone accuses me of saying "never refactor anything," let me be crystal clear: I'm not against refactoring. I'm against stupid refactoring.

Good refactoring happens when:

  • You're fixing a bug and realize the code structure is making it hard to fix correctly
  • You need to add a feature and the current design genuinely makes it difficult
  • The code has become a bottleneck because the team keeps making mistakes in it
  • You're extracting duplication that has actually been causing problems when things change
  • Performance issues require restructuring

Bad refactoring happens when:

  • The code works fine but doesn't match your aesthetic preferences
  • You're refactoring "just in case" we might need flexibility later
  • You're applying patterns from a book without understanding if they solve a real problem
  • You're breaking up functions purely to hit some arbitrary line count target
  • You're making the code "more testable" when the tests are already working fine

Notice the difference? Good refactoring solves actual problems. Bad refactoring solves theoretical problems while creating real ones.

The Clean Code cult has convinced developers that refactoring toward some idealized structure is always good. It's not. Refactoring has costs: time, bugs, cognitive overhead for your team. Those costs need to be justified by real benefits, not imaginary future scenarios.

So refactor away. Just make sure you're doing it for the right reasons.

The Bottom Line

Clean Code sold you a lie: that good code is about following rules.

Good code is about understanding trade offs. It's about context. It's about knowing your team and your domain and making informed decisions, not performing rituals from a book.

Uncle Bob isn't your friend. He's a guy who wrote some books in the 2000s and built a profitable consulting empire around them. His advice might have been relevant for enterprise Java development 15 years ago. It might even be relevant for your specific situation today.

But it's not gospel. It's one guy's opinion, filtered through his specific experiences and biases, packaged into a product.

You're allowed to disagree. You're allowed to think for yourself. You're allowed to write code that works, even if it wouldn't pass Uncle Bob's code review.

In fact, I'd argue you're better off doing exactly that.

Top comments (6)

Collapse
 
peacebinflow profile image
PEACEBINFLOW

Yeah… this is cathartic in the best way.

What you’re really calling out here isn’t Clean Code itself, it’s rule worship. The moment principles turn into checklists, thinking quietly leaves the room. I’ve seen the same thing you describe: working code refactored into something “purer,” only to become harder to reason about and easier to break. But hey—green checkmarks on the doctrine.

The DRY point especially resonates. Duplication is visible and honest. Bad abstraction is invisible debt. I’d rather read two similar functions that I can change independently than spelunk through a hyper-generalized “solution” that exists mainly to satisfy a principle. Six months later, nobody remembers why it was abstracted—only that touching it feels dangerous.

And the comments bit? 100%. Code can explain what, not why. Removing context because “good code is self-documenting” is basically assuming the future reader shares your brain, your constraints, and your moment in time. That’s… optimistic.

What I appreciate most is the framing of good code as something teams can live with. Not admire. Not lecture about. Live with. Modify without fear. Ship without ceremony. That’s the part that gets lost when reviews turn into principle enforcement instead of shared understanding.

Clean Code as guidance? Useful.
Clean Code as law? Exhausting.

The best engineers I’ve worked with don’t quote rules—they explain tradeoffs. They know when to be elegant and when to be boring. And boring code that works is wildly underrated.

This post feels like permission to think again instead of pattern-matching. Honestly refreshing.

Collapse
 
xwero profile image
david duymelinck

Clean Code as guidance? Useful.
Clean Code as law? Exhausting.

This is the way most concepts should be interpreted.
Take the parts that help you write better code, and leave the parts that make code worst.
This can vary from application to application.

Collapse
 
paul_danger_kile profile image
Paul Danger Kile • Edited

If I have code that does the same exact thing, then that should be a function.

If I have code that doesn't do the same exact thing, but follows a similar algorithm, then that should NOT be abstracted into a common function. In this case, the author used a pattern and patterns should occur in multiple places. (It might not be a named Gang of Four pattern, but it's a pattern nonetheless.)

Don't refactor working code.

To be sure: I don't disagree with anything that you wrote here. I just wanted to share my strategy regarding this subject.

Collapse
 
rakesh_narang_a948cb194cc profile image
Rakesh Narang

i like clean code that is compliant with DRY and SOLID principles

but i am also careful enough to not follow it for all the features

on Friday, i asked cursor to rewrite a workflow using DRY and SOLID - it created 5-6 files out of a single service class

the workflow was not worth the effort , so i asked it only to refactor with DRY and it became more readable


today i asked cursor to refactor another workflow using DRY and SOLID , this time cursor proposed only 2-3 additional files which actually improved the readability of the service

so i accepted the changes, ran the comprehensive test suite and pushed the code to dev


as a senior engineer you must have the decision making skills as to when to follow clean code guidelines and when to skip them

Collapse
 
ecdub27 profile image
EC Wiegand

Great take! Like honestly 😂

Collapse
 
_9942848bd8d9e58b9b7f7aa profile image

feel

Some comments may only be visible to logged-in visitors. Sign in to view all comments.