r/programming • u/Mastbubbles • 1d 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
10
u/Downtown_Cat_7425 1d 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.
5
u/CrabHuntLover 1d ago
Comments are for yourself when you come back to read that code in 3 months.
3
u/JadisGod 13h ago
Sometimes I add comments just because the different syntax coloring turns them into an aesthetic separator. It makes group sections feel better and enables visual skimming.