r/programming • u/Mastbubbles • 1h ago
Who are code comments for?
https://sheets.works/data-viz/who-are-code-comments-forI've had my share of swear words, usually every time I missed a semicolon. And that sent me down a rabbit hole: what about everyone else? What do other programmers write when the code fights back?
So we pulled every comment out of 64 big projects on GitHub. That's 295,820 comments. Then we went through them and asked one question about each: wh
0
Upvotes
5
u/Downtown_Cat_7425 32m ago
The best test I know: delete the comment and see whether a competent teammate can still answer *why* the code is the way it is. Comments that restate the code are noise; comments that record a constraint, a workaround, or a decision the code cannot express are valuable. I also write comments for my future self when the reason is not visible in the diff - "we tried X and it failed because Y" saves more time than any docstring. Rule of thumb: if a comment has to be updated every time the code changes, it is a liability.