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

1

u/AssiduousLayabout Mar 06 '25

I don’t understand how turning a method with 20 lines into 13 separate methods is supposed to make the code more readable.

I think there's two benefits to breaking code into smaller chunks, even when you don't immediately need to reuse things:

  1. You can test the pieces independently and validate their behavior.
  2. It helps you limit and define the interactions between parts of the code that were not intended to directly interact. For example, I will generally split loop bodies of significant complexity into a single method that takes whatever we're iterating over. Besides readability, it comes with the benefit that you can't accidentally leak local variables between one iteration of the loop and the next, as could happen if a variable is only conditionally set.

I also personally encounter methods that are way too long substantially more than methods which are too short, so erring on the side of shorter methods is probably a good plan.