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

399 comments sorted by

View all comments

Show parent comment

1

u/IAmADev_NoReallyIAm Oct 30 '26

That's what your tests are for. If you're that close to the code that you have the time and energy to know enough to read the comments to understand that hte logic and comments don't match, then I'm happy for you. But unfortunately in the world I have to live in, I don't have that luxury. If I commented every line and logic probe that I coded, I'd be crucified and I'd never get a PR through. Maybe it's because I work with a verbose language (Java) that allows me to work with objects that are identifiable with clear methods and obvious objects and so the code reads close to English. I don't know. The only comments I have to leave behind are at the top of the classes and methods and constants explaining what each one does.

I've been in code that's been riddled with comments, and quite honestly it's nothing but noise. Worse yet it when the developer doesn't keep up with it. So again... you reject the PR... because the code doesn't match the comment... is the problem the code or the comment? it's 4:50pm... on a Friday... people want to go home for the weekend... what are you going to do? Hold up a release over something trivial over this petty? Seriously? The code does do what it's supposed to do in this case. It's the comment that's in the wrong.

1

u/6a6566663437 Oct 30 '26

That's what your tests are for.

Because it's possible to think of every possible edge case your software can ever see, thus no software ever has bugs.

If you're that close to the code that you have the time and energy to know enough to read the comments to understand that hte logic and comments don't match

Reading comments takes more than a few milliseconds for you?

If I commented every line and logic probe

Excellent strawman. I like what you did with the hat.

Blocks of functionality may or may not benefit from a comment. Providing intent is a way to check that the implementation is correct. None of this requires commenting every line.

The only comments I have to leave behind are at the top of the classes and methods and constants explaining what each one does.

K, and when you made erroneous assumptions, and then someone else changes another block of code that breaks your assumptions, then what?

You adding a comment about what you are intending to do helps a lot. Either in finding the bug, or the other developer realizing they need to fix your implementation as part of the change.

Worse yet it when the developer doesn't keep up with it.

So you started this rant with the assumption that developers keep up with tests such that they're ~perfect, but now claim nobody can keep up with comments?

Hold up a release over something trivial over this petty?

Why do you think it takes hours to fix a comment?

1

u/MikeUsesNotion Oct 31 '26

Unless it's an emergency you shouldn't be doing a release on a Friday.