Comment Quality
6 exercises — spot anti-patterns (lying comments, obvious comments, journal comments, commented-out code) and rewrite them to high standard.
0 / 6 completed
Comment anti-patterns to spot
- Obvious comment: restates what the code says ("add 1 to x")
- Lying comment: describes different behavior than the actual code
- Journal comment: changelog entries ("Alex, 2022: added X") — use git
- Commented-out code: dead code — delete it; git preserves the history
- Noise comment: vague ("this is important") — say WHY and what breaks if changed
- Over-comment: dense comments on obvious code; justified only for non-obvious algorithms
1 / 6
Identify the anti-pattern in this comment:
x = x + 1; // add 1 to xObvious comment — the most common comment anti-pattern. The comment adds no value; anyone who can read code already knows
Fix: either delete the comment, or replace it with a WHY comment:
•
•
Comment quality anti-patterns:
1. Obvious comment: restates the code ("add 1 to x")
2. Lying comment: describes different behavior than what the code does
3. Journal comment: "Added by Alex on 2023-07-14" — use git blame instead
4. Commented-out code: dead code left in the file — delete it, git history preserves it
5. Noise comment: empty, placeholder, or meaningless ("TODO: fix later")
When code is well-named and obvious, no comment is the best comment.
x = x + 1 adds 1 to x.Fix: either delete the comment, or replace it with a WHY comment:
•
x = x + 1; // advance past the BOM character at offset 0•
x = x + 1; // skip index 0 — reserved for the null sentinel valueComment quality anti-patterns:
1. Obvious comment: restates the code ("add 1 to x")
2. Lying comment: describes different behavior than what the code does
3. Journal comment: "Added by Alex on 2023-07-14" — use git blame instead
4. Commented-out code: dead code left in the file — delete it, git history preserves it
5. Noise comment: empty, placeholder, or meaningless ("TODO: fix later")
When code is well-named and obvious, no comment is the best comment.
Next category: Debugging Language →