Agent Wranglers

ARC-23Recommended

Say why, not what

A comment states a reason the code cannot show, such as a bug in another system, a legal rule or a measured trade-off. It never repeats what the code does.

How to do it

Before writing a comment, ask if it would still be true after a rename. If it describes the code, improve the code instead. If it records a decision, keep it short and link the source, such as a bug report or a measurement. Record a larger decision in a decision record and link it.

Examples

Python example

# Bad: repeats the code
# add one to the count
count += 1

# Good: a reason the code cannot show
# The payment provider retries webhooks for 72 hours, so keep seen IDs that long.
SEEN_WEBHOOK_TTL = timedelta(hours=72)

TypeScript example

// Bad: repeats the code
// add one to the count
count += 1;

// Good: a reason the code cannot show
// The payment provider retries webhooks for 72 hours, so keep seen IDs that long.
const SEEN_WEBHOOK_TTL_MS = 72 * 60 * 60 * 1000;

How to check

A script drops short words such as the and to from each comment. It fails the comment when every word left also appears in the next line of code. The comment-share script from Let the code explain itself keeps the total under 10%.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/architecture/comments/comments-say-why">Agent Wranglers clean code and architecture playbook</a>. In code you write, add a comment next to it with the same link.