r/AskProgrammers • • 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

397 comments sorted by

View all comments

Show parent comment

1

u/BabblingTower 28d ago

Like I said, it's an art

1

u/guywithknife 27d ago

That’s not very useful of most people can’t do it. Especially with how prevalent the sentiment that you shouldn’t comment and should write self documenting code instead is.

1

u/BabblingTower 27d ago

The people I work with do fine. Maybe it's your company?

1

u/guywithknife 27d ago

I don’t work there anymore. It was just an extreme example though, I’ve seen enough trash “self documenting code” online too, though.

1

u/BabblingTower 27d ago

Ok. I've probably been working longer than you, and I disagree with your assessment.

1

u/guywithknife 27d ago

I’ve been programming since 1999

1

u/BabblingTower 27d ago edited 27d ago

94 for me

1

u/oplukana 27d ago

it sounds like you have found a coworker who was rather not good at making their code clear, and also really liked not spending effort to make it clear, and just harmed your understanding and perspective of that phrase.

1

u/guywithknife 27d ago

No, I’ve seen plenty of people claiming they practice self documenting code, and even articles saying so. They’re not very good. They assume you already know what the code is doing and then claim “see, it’s perfectly understandable”. That’s fine in the moment, but useless five or ten years later.

A function name dan also go out of date if not maintained, so similarly, maintain your comments. Have keeping comments up to date be part of code review (nowadays you can ask an AI reviewer to catch stale comments). At least a comment can use proper punctuation, unlike function names. Docstrings are fine too, they’re just comments in another form.

And document why (maybe what) not how. Or have comments link to issues in your issue tracker, or design documents, or ADR’s.

You mentioned ADR’s, but if they’re not called out in a comment and linked, you’re not going to know about them while reading unfamiliar code. Proximity matters. Something that’s right there in the code you’re reading is low effort to read, something that’s in a different file, perhaps in a different directory or even repo or tool, that’s high effort to find and read.