Re:On Comments in Code
by cush on Wednesday June 16, 2021 @01:55AM
(#27525343)
Until the code changes, then the comments are usually worse than nothing
[ Parent
| on HN ]
No. Comments are like a parity check. If the comments don't match the code, then you know that either:
1) The comments are correct, but the code is wrong. This is a bug. 2) The comments are wrong, but the code is correct. This is equally a bug. Whoever makes the change has an obligation to describe their changes with a comment.
Code with no comments? Could be right, could be wrong, who knows?
Good luck maintaining that.
I wish I could upvote your comment more, but putting it in my bookmarks will have to do for now.
Re:On Comments in Code
by AlotOfReading on Wednesday June 16, 2021 @03:38AM
(#27525921)
I've seen this counterpoint brought up many times before, but I'm struggling to think of the last time I experienced it. Is it really a common problem for you?
Yes, the issue isn't that most comments are inaccurate, it's that the inaccurate ones are so costly. When the comment doesn't match the code, it makes you question the code and the intent. 90% of the time, comments are accurate or just redundant (the code is descriptive enough), but that 10% of the time when the comments says A and B is happening, I end up chasing down whoever or digging through changelogs and tickets to find the comment wasn't updated.
For the kind of code comment we started this thread talking about (explaining why some simpler/more obvious process is not used), this seems vanishingly unlikely.
Then you fire the coder who changed the code without updating the comments?
Most code doesn't need comments.
Re:On Comments in Code
by kwhitefoot on Wednesday June 16, 2021 @05:49AM
(#27526671)
That's a waste. Just train them better.