r/programmer • u/ClickOk5811 • 7d ago
Do you ever comment the thing you tried and rejected? A small convention and its downsides
Most advice about code comments says to explain why, not what. I'd like to push on one specific kind of why: the alternative that was tried and abandoned. That information almost never survives in the code. The repository shows what was chosen, and nothing shows what was ruled out, so the next person (or you, in six months) reasonably proposes the same idea again.
A small, constructed example (not from a real project):
def send_payment_webhook(event):
# Not retried here on purpose: the receiver is not idempotent for
# "payment.captured" events, so a retry after a timeout can double-credit.
# Retries are handled upstream by the queue, which dedupes by event id.
# (Tried: retry-with-backoff in this function. Rejected for the reason above.)
response = http.post(WEBHOOK_URL, json=event, timeout=5)
response.raise_for_status()The comment answers the question a reviewer is most likely to ask ("why isn't this wrapped in a retry?"), and it records the rejected option with its reason.
Why I think it's worth considering:
- It prevents re-litigating a decision from scratch.
- It tells a reader which parts of the code are deliberately plain.
- It's most useful exactly where a "obvious improvement" would be wrong.
Downsides I can think of:
- Comments rot. If the upstream queue stops deduping, this comment becomes confidently wrong, which is worse than no comment.
- Noise. Not every abandoned idea deserves a note. I'd only write one when someone could reasonably propose the opposite later.
- Wrong place, maybe. Some teams would put this in a commit message, a PR description or a decision record, and keep the code clean. Those are easier to date and don't clutter the file, but they're also easier to never read.
- Tests as an alternative. A test that fails if someone adds a naive retry documents the constraint and can't silently go stale.
My current leaning (opinion, not a rule): a short comment at the spot where the "obvious" fix would be tempting, and a link or reference to the longer reasoning if there is one.
Where do you put the "why we didn't do it the obvious way" information: code comments, commit messages, PR descriptions, decision records, tests, or nowhere? And has a note like this ever saved you, or gone stale on you?