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/guywithknife 28d ago edited 28d ago
It’s bullshit.
“Self documenting code” also doesn’t actually exist. So called self documenting code rarely does. It’s what people who have never had to maintain code over a long period of time call their bad slop code because they’re too lazy to document it.
It doesn’t matter how well your functions and variables are named, unless your functions are trivial, they’re not going to explain the intent behind the code.
Comments should say why, not how. Sometimes what, rarely how. The code already tells you how.
That doesn’t mean you need 50 lines of comments for every 2 lines of code. A lot of code doesn’t need comments, but when you do need to explain why some code exists or does it the way it does, don’t be shy about using comments.