principle-minimal-comments
Installation
SKILL.md
Minimal Comments
Code explains itself, or it gets rewritten until it does. A comment is the last resort for the rare line that still reads as a mistake after that: a workaround for something outside the code that no name can carry.
Why: A comment is a second copy of an intent the code already states, and copies drift. Every comment spent on the obvious taxes the one that matters, and a reader cannot tell the load-bearing one from the noise.
The rule
- No comments by default, inline or at a unit's head: not the step a line takes, the branch a condition guards, the phase a block belongs to, the mechanism a value compensates for.
- The urge to comment means the code is unclear. Fix the code instead: name the value (
const scrollViewInsets = headerHeight + insets.bottom), extract a function whose name says why, split the expression, restructure the branch. Then drop the comment you were about to write. - The bar for survival is a workaround for something external, such as a platform bug, a library quirk or a timing constraint, that reads as a mistake and invites a "fix" without the comment. Name the external cause in a line. Nothing else clears it: not an invariant the types or an assertion can carry, not an explanation of layout or arithmetic, not why the code has this shape.
- A workaround that reads as ordinary code gets none: a
jest.mockplaced before arequireis how tests look, whatever quirk of the toolchain forced the order. - A named constant or extracted function is the comment. Its name carries the whole explanation, so nothing sits above it: not a doc block, not the sentence the inline comment was going to say. A design value such as a spacing, an offset, a scale or a limit is a number someone chose, and the reason it looks right is taste, not a workaround:
const OFFSET = 16;and nothing else. - Doc comments: at most one per exported function, type or module, and only when the name and signature leave a question a caller must answer.
getUserById(id: string): User | nullleaves none, so/** Returns the user with the given ID, or null if none exists. */goes. Behavior spanning units lives in the document read before the code, never repeated in it.
Surrounding code is not precedent
The pull to comment rarely comes from the code at hand. It comes from the file around it, a docstring habit, or a language whose tooling expects a doc block on every declaration.