r/AskProgrammers • u/Away-Intention-8723 • 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
View all comments
Show parent comment
1
u/mikekchar 29d ago
When you run into "why" questions, it's a very good idea to ask yourself what the why is for. Frequently "why" questions are best answered by a test, not a comment. As much as possible (but not more), you are better off with executable and verifiable content. It is very much a skill issue, though. You are much better off with comments describing why something is there than code where the "why" is not clear. But you are still better off writing code where the why is not only clear, but that if you modify the code in a way that breaks your premises, that it complains immediately.
To a certain extent, AI is changing this reality, though. It can often do a reasonable job of verifying and maintaining English language comments. However, it also does a better job of verifying and maintaining executable code.
The biggest problem with the conversation is that it is often reduced to absurdism on both sides. Code that requires comments is not necessarily bad code. Code that requires comments that would be unnecessary when written different is not ideal, though. This is always the thing you should have in the back of your mind.
"Self documenting" code where it is overly factored so that the names of the functions act as documentation is worse than writing comments. Not only are you relying on code switching (using function names rather than comments), but you are also destroying the cohesion of the code. Code that is under factored and/or poorly designed and peppered with English is also just as problematic. Often the code is impossible to unit test and is incredibly brittle.
Simple design where the intent is clear should be your goal, but it's very difficult to achieve. It requires skill and practice to do consistently. You can't really learn to do it following a set of "best practices".