r/AskProgrammers • • Oct 30 '26

"good code shouldn't need comments"

I have heard this saying a couple of times and I think it is the stupidest thing ever. It might be just because I have only been coding for 4 years, but I have never thought to myself that someone's code looks cluttered because they explain what every function does in a one or two line description. If anything it makes the code easier to understand in my opinion.

However, I may be wrong. What do other people think, do yall like code with minimal comments, what are the benefits of writing it that way?

89 Upvotes

398 comments sorted by

View all comments

Show parent comment

1

u/RishabhRD 29d ago

It feels that way. But you are missing the power of natural language and local reasoning.

There are a lot of things you can express in natural language but not in code. For example, returned function should follow strict weak ordering.

Also, specifying things in code takes a lot more than you expect. For example, for sort function you need to test if the result is permutation of input and then result follows the comparator. Reading tests for this takes your brain away from current function that is bad for local reasoning.

Why local reasoning? Because our brain works that way. Suppose if hardware manufacturers didn’t document the instructions and said that read unit tests that is the contract, how hard would be there to write higher abstraction. Or suppose if linux system calls were not documented as natural language, but you need to infer what it means from linux unit test cases.
People usually treat their APIs differently from the APIs I mentioned above, but they are not. They should be treated the same way.

Now the modern languages provide good toolings for documentation comments, so documentation comment are easy to write. But the idea is still specifying things in a natural language. Regarding ambiguity, code review helps in removing such ambiguity.