← CodeClarityLab Home
Browse by Category
+ added · updated 7d
← Back to glossary

Comments as Code Smell

quality Beginner
debt(d5/e3/b3/t5)
d5 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'specialist tool catches it' (d5). The term's detection_hints.tools lists phpcs, phpmd, phpstan which can flag some comment patterns (TODO without ticket, commented-out code blocks, excessive comment density), but nuanced judgment about whether a comment is genuinely redundant vs valuable 'why' context often requires human review. Automated detection catches the obvious cases but not the subtle smell.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3). The quick_fix indicates refactoring code to be self-explanatory — this typically involves renaming methods/variables, extracting functions, or deleting redundant comments. Not a one-line patch (e1), but usually localized within a single component. Removing TODO comments or commented-out code is simpler; improving naming to eliminate what-comments requires more thought but stays within one file.

b3 Burden Structural debt — long-term weight of choosing wrong

Closest to 'localised tax' (b3). Comment smell is a style/quality concern that affects readability but doesn't impose architectural weight. It applies across all contexts (web/cli/queue-worker) per applies_to, but poor commenting practices don't create load-bearing dependencies or shape the system's structure. The debt stays localized to the files where comments exist — fixing one area doesn't require touching unrelated code.

t5 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'notable trap' (t5). The misconception states developers believe 'more comments always make code better' — this is a documented gotcha that experienced devs eventually learn, but juniors commonly fall into it. The trap isn't catastrophic (t9) because the failure mode is noise and drift, not broken functionality. Many developers have been taught to comment liberally and must unlearn that what-comments are harmful while why-comments remain valuable.

About DEBT scoring →

Also Known As

bad comments comment overuse redundant comments

TL;DR

Excessive or explanatory comments often indicate that the code itself is too complex or poorly named to be self-explanatory.

Explanation

Martin Fowler describes comments as a deodorant: they mask the smell of code that needs refactoring. A comment explaining what a function does suggests the function should be extracted and given a better name. Comments explaining why a non-obvious decision was made are valuable and should be kept. Outdated comments that contradict the code are worse than no comments. The goal is code so clear it needs no explanation, with comments reserved for intent that cannot be expressed in code.

Common Misconception

More comments always make code better. Comments that restate what the code obviously does add noise and drift out of sync with changes. The smell is not comments in general but comments that exist because the code is too unclear to speak for itself.

Why It Matters

Comments that explain what code does (rather than why) are a symptom — the code itself should be clear enough that what-comments are unnecessary. Over-commented code often hides poor naming or structure.

Common Mistakes

  • Adding comments to explain what a method does instead of improving the method name.
  • Leaving TODO comments without a ticket reference or owner — they accumulate and are never addressed.
  • Commented-out code left in production — use version control; dead code confuses readers.
  • Block comments that restate the function signature: /** Gets the user */ function getUser() — zero information.

Code Examples

💡 Note
A comment that restates the code is a sign the code needs better naming. Comments explaining intent, trade-offs, or non-obvious constraints are genuinely useful.
✗ Vulnerable
// Get the user
\$user = \$this->userRepo->find(\$id);
// Check if admin
if (\$user->role === 'admin') {
    // Grant access
    \$this->grantAccess(\$user);
}
✓ Fixed
// Self-documenting — no comments needed
\$user = \$this->userRepo->findOrFail(\$id);
if (\$user->isAdmin()) {
    \$this->grantAdminAccess(\$user);
}

// Comments add value when explaining WHY, not WHAT:
// 5-second delay: payment webhook arrives asynchronously;
// the DB write may not be committed when the redirect fires.
sleep(5);
\$order->refresh();

Added 15 Mar 2026
Edited 22 Mar 2026
Views 30
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings F 0 pings S 0 pings S 1 ping M 0 pings T 0 pings W 0 pings T 1 ping F 1 ping S 1 ping S 1 ping M 0 pings T 0 pings W 0 pings T 0 pings F 2 pings S 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S
No pings yet today
No pings yesterday
Perplexity 8 Amazonbot 7 Ahrefs 4 Unknown AI 4 Google 2 ChatGPT 1 SEMrush 1
crawler 25 crawler_json 1 pre-tracking 1
DEV INTEL Tools & Severity
🟢 Low ⚙ Fix effort: Low
⚡ Quick Fix
When you feel the urge to write a comment to explain what code does, refactor the code to be self-explanatory instead — comments that explain why are valuable; comments that explain what are code smells
📦 Applies To
any web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
// increment counter $i++; Comment repeating code. // TODO: fix this (months old). // This is a hack. Commented-out dead code blocks
Auto-detectable: ✓ Yes phpcs phpmd phpstan
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: High ✗ Manual fix Fix: Low Context: Function

✓ schema.org compliant