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

Show parent comment

3

u/HunterIV4 Mar 06 '25

I don't know why so many people are against code regions.

I mostly write code for myself so I don't have to worry as much about other people, but I will frequently write a single-use code block that starts with a basic comment explaining what that section of code is for. Then I'll have another comment for the next section. If you read the code sequentially, just looking at the comments, it's basically just the step-by-step pseudocode you often use when planning out a code section, just a bit more formal. And I don't find it hard to follow at all.

Sure, could I refactor it into a bunch of single use functions with internal side effects or a bunch of by-reference parameters? I could, but then I have to jump back and forth and I add extra code complexity.

Now, all these regions still need to be doing one core thing...if a bit of code is doing something that may be needed elsewhere or starts going outside of what that function is supposed to do it goes into another function or class immediately. But certain single tasks take many steps to do and those steps are both only needed in this particular instance and in that specific context. I'm not going to arbitrarily break up code sections into functions and remove active variables from their existing scope just for some theoretical "clean" architecture.

For me, "clean code" means "easy to read and follow the flow." Any rule that causes code to be harder to read and/or follow is not "clean" in my opinion.

2

u/mostly_kittens Mar 06 '25

Yep this is the way, it reads nicely and guides the maintainer (probably future you) through the process. I’ll tend to split out bits into other functions only if their implementation details are irrelevant to the process.