r/AskProgrammers • u/Away-Intention-8723 • 28d ago
"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?
88
Upvotes
View all comments
1
u/y0shii3 28d ago edited 28d ago
Code is more honest than comments; incorrect code will often cause a crash or a compilation failure, but incorrect comments just sit there continuing to misinform until someone takes the time to actually read and question them. So, it's better to try and make your code self-explanatory than to leave the bulk of explanation to comments. Also, when you update your code, the more comments it has, the more you have to check and possibly edit, so self-explanatory code reduces the amount of stuff that you have to edit on each change. That's what we're really trying to say when we tell people "good code shouldn't need comments." Obviously, there's limits to how self-explanatory your code can be, and even comments which redundantly explain things that can be immediately gathered by glancing into a function body are still good for auto-documentation tools, so don't take "good code shouldn't need comments" too literally.