| name | Commenting Intent |
| description | Comment WHY code exists and non-obvious decisions, not WHAT code does (mechanics) |
| when_to_use | When adding comments to code. When explaining complex algorithms. When documenting decisions. When code review requests more comments. When over-commenting obvious code. When comments just restate code. When magic numbers exist. When non-obvious decisions made. When future maintainer would ask "why this way?". |
| version | 1.0.0 |
| languages | all |
Commenting Intent
Overview
Good comments explain WHY, not WHAT. Code already shows what it does. Comments should explain intent, decisions, and non-obvious reasoning.
Core principle: If the comment just restates the code, delete the comment or improve the code.
Baseline Violation
Agents comment mechanics (what code does):
❌ Over-commenting (baseline):
subtotal = sum(item.price * item.quantity for item in items)
tax = subtotal * tax_rate
total = subtotal + tax
Problem: Comments just restate obvious code. No value added.
✅ Comment intent only:
def calculate_total_price(items, tax_rate):
"""Calculate order total including tax."""
subtotal = sum(item.price * item.quantity for item in items)
tax = subtotal * tax_rate
return subtotal + tax
What to Comment
1. Non-Obvious Decisions
✅ WHY you chose this approach:
def is_rate_limited(user_id, redis_client):
key = f"rate_limit:{user_id}"
current = redis_client.get(key)
if current is None:
redis_client.setex(key, 60, 1)
return False
return int(current) >= 100
Explains: WHY Redis, WHY these limits, WHERE requirements came from.
2. Algorithms and Complex Logic
✅ WHY this algorithm:
def find_user(users, email):
return binary_search(users, email)
Explains: WHY binary search, WHY pre-sorted, trade-off reasoning.
3. Magic Numbers and Constants
✅ WHY these values:
MAX_RETRIES = 3
TIMEOUT_MS = 5000
BATCH_SIZE = 100
Explains: WHERE values came from (testing, SLA, incident).
4. Workarounds and Gotchas
✅ WHY unusual code:
client.reset()
client.reset()
Warns future maintainer: Unusual code has reason, link to issue.
What NOT to Comment
Don't Comment Obvious Code
❌ Restates the code:
user.name = "John"
for item in items:
process(item)
✅ Let code speak:
user.name = "John"
for item in items:
process(item)
Don't Comment Mechanics of Standard Patterns
❌ Obvious pattern:
left, right = 0, len(arr) - 1
while left <= right:
✅ Comment intent only:
def binary_search(arr, target):
left, right = 0, len(arr) - 1
while left <= right:
The Comment Test
For each comment, ask:
-
Does it explain WHY, not WHAT?
- WHY: "Redis for distributed limiting" ✅
- WHAT: "Get value from Redis" ❌
-
Would I understand without it?
- If yes: Delete comment
- If no: Keep comment OR improve code clarity
-
Does it add information beyond the code?
- Yes: Keep it
- No: Delete it
Quick Reference
| Comment This | Don't Comment This |
|---|
| WHY you chose this approach | WHAT the code does |
| Non-obvious decisions | Obvious assignments |
| Magic number sources | Standard patterns |
| Algorithm trade-offs | Mechanics of loops/conditionals |
| Workarounds and gotchas | Self-evident operations |
| Business rule origins | Variable declarations |
Real-World Impact
From baseline:
- Agents commented every line of simple price calculation (over-commenting)
- Comments restated code without adding value
- Missed opportunities to explain WHY (decisions, trade-offs)
With this skill: Comment intent, not mechanics.
Integration with Other Skills
For evergreen comments: See skills/writing-evergreen-comments - no temporal context in comments
For self-documenting code: See skills/naming-variables - good names reduce need for comments