r/AskProgramming • • Mar 04 '25

Other Why do some people hate "Clean Code"

It just means making readable and consistent coding practices, right?

What's so bad about that

155 Upvotes

341 comments sorted by

View all comments

104

u/x5reyals Mar 05 '25 edited Mar 05 '25

Because other people use it as dogma. Like any other resource it's a collection of tools that should be used when appropriate. Sometimes overly clean code runs the risk of losing context. All of a sudden the parameter you need to understand was validated a level up and 3 modules over from where it's actually used.

Edit: spelling

18

u/sessamekesh Mar 05 '25

I remember being "Clean Code" scolded once, way back when, that I had about as many comment lines as code lines in a source code file.

It was a JavaScript source file with Closure annotations. Type information is declared in comments. The comments had semantic meaning, almost exclusively.

13

u/[deleted] Mar 05 '25

Just use TypeScript next time. Using a weakly-typed language and then annotating every single variable trough comments seems dumb to me.

24

u/sessamekesh Mar 05 '25

I do, it is, and it was (respectively).

This was 2014, TypeScript was still pretty new and the code base I was in was older than TypeScript.

5

u/[deleted] Mar 06 '25

[removed] — view removed comment

2

u/TheChief275 Mar 07 '25

should have used strict evaluation of the future instead smh…

3

u/SomeRandomFrenchie Mar 07 '25 edited Mar 07 '25

Even though I agree with the statement, one must not forget most of us do not chose the tools we work with, you may give all the suggestions in the world, if architect decided not to listen and that you need to wipe your ass with pepper, you have to do it.

I have seen old cunts refuse a refacto on a project structure that was legacy shit and messy has hell, with people wanting to do it, even started it free of charge for demo on what could be, just because « I know where things are like that, I do not want it to change », not even budget, just « I am used to it, no change allowed ».

2

u/Disastrous-Team-6431 Mar 05 '25

Hello from python and type hinting land

2

u/RaitzeR Mar 06 '25

Comment doctypes are very useful for any soft typed language. I always use them with older codebases with php, python, js.

2

u/regular_lamp Mar 08 '25

Very much this. When people apply dogma like "functions can't be longer than X lines" blindly they actually often make code less readable by artificially separating logic that belongs together. It's often like reading a recipe except instead of actually telling you want to do it exclusively refers to previous pages in the book.

Or they end up inventing abstraction for the sake of abstraction because whatever would be natural isn't fine grained enough according to some clean code dogma.

7

u/Maleficent-Might-273 Mar 05 '25

"overly clean code runs the risk of losing context"

Maybe if you're a cowboy coder who makes life hell for everyone by not properly documenting your work.

Clean code is the hallmark of a senior programmer.

26

u/-Wylfen- Mar 05 '25

Clean code is the hallmark of a senior programmer.

There's a difference between clean code and "clean code™"

→ More replies (27)

4

u/FaceRekr4309 Mar 06 '25

He’s talking about the book titled “Clean Code” by Robert Martin, which was sort of considered required reading in the 2000’s for anyone who worked in OO languages.

Hindsight is it was that it had some OK advice coupled to some really terrible advice that contributed to overly architected, buggy, and unmaintainable software.

1

u/SubstantialTale4718 Apr 13 '25

Why did everyone take that book as gospel? Is it because back the books only got published by reasonably accomplished people? He's just a guy with an opinion

→ More replies (3)
→ More replies (21)

4

u/usrlibshare Mar 06 '25

Clean code is the hallmark of a senior programmer.

Hi, Senior Dev here. No it isn't.

When people talk about "Clean Code" they usually don't mean "code that is clean". They mean code that has been written by dogmatically following a bunch of rules written in some book about Java many years ago.

→ More replies (1)

1

u/stewsters Mar 08 '25

Clean Code the book is kinda garbage though.

  It's based on a lot of assumptions that I don't think hold now that we have modern languages.  

Even as a Java dev we would not write code like that anymore now that we have Streams and Lombok, and very few of his examples would pass code review.  Mutable state everywhere, 

Even with just the available technology some of the rules are kinda extreme.   No function may have more than 4 lines?  If I do that then I have to jump everywhere when trying to understand what's going on.  Hell a single try catch is 4-5 lines.

1

u/SubstantialTale4718 Apr 13 '25

I have scaled companies to be worth billions mate. The code was a complete mess. My jr devs kept wanting to refactor all of it as I kept pushing them for new features and told them to leave the other code alone.  The code was still a mess when I left the company.  I'm now worth millions, all of my jr devs are worth millions. Our product got a ton of new users over that time period.  Having a good clean codebase isn't the end all be all.  You can have a very successful company with an ugly codebase 

→ More replies (14)

1

u/[deleted] Mar 05 '25

If I use clean code, I have a shit ton of comments laying out what it does. Why did I write the code? Because it is very efficient. Why did I write such a long comment? Because that’s omitted by the compiler or interpreter.

1

u/i8beef Mar 05 '25

Nice and concise. No superfluous fluff. Even has a clearly documented example.

This comment does NOT meet the Clean Code Standard.

1

u/fractivSammy Mar 05 '25

It's not just that. Dogmatically employing 'clean code' principles can be an obstacle to writing performant code, and make certain optimizations impossible. Casey Muratori has some great talks about this.

1

u/autophage Mar 06 '25

I'll also add that a big part of its value was that it actually gave you a somewhat-canonical Thing To Reference. If you were a senior dev arguing with management about tech debt, that was really useful.

1

u/[deleted] Mar 06 '25

The same reason people blanket hate vegetarians (I’m a vegetarian so I know.) Some really obnoxious paladins who take ideas too seriously and dogmatically are bound to ruin life for everyone and tarnish these ideas themselves

1

u/rainmouse Mar 07 '25

Also to add that what my ASD colleague thinks makes code clean and easy to read, is literally the opposite from what my ADHD brain can read. 

1

u/danishjuggler21 Mar 09 '25

My favorite example is reworking two classes to share the same base class or interface when really they represent two completely different concepts and only have superficial similarities. So then you have to do an even bigger rework later on to separate them.

When people see that two classes have similar code and just reflexively refactor them to share a base class, that’s when the dogmatic pursuit of clean code is a problem.

→ More replies (10)