R88 Comment only what the code cannot say

Off by default

Write a comment inside code only to say what the code cannot say for itself, such as why it is done this way.

Reason

A comment that repeats what the code plainly does is a second copy of it (Art. VIII §5): it adds reading and upkeep and nothing else (Art. III §4), and once the code changes without it, it is wrong.

Verification

The rule covers comments inside the code. A doc comment or docstring that states an interface, its parameters, return value and errors, for readers who do not read the body, is documentation and not covered, even where it repeats a signature.

Violated when a change adds a comment inside code that says only what the code next to it says plainly, such as # add one to the counter above count += 1.

Provisions of the constitution it cites

Relations

Parent
R83 Code
Requires
none
Conflicts with
none

Metadata

ID
88
Revision
2
Kind
rule
Status
trial
Slug
comments-say-what-code-cannot
Default level
project
Constitution revisions
>=1
Check
none
Default
off
Uses
Instructions instructions, Review review
Original language
English en
Translations
Chinese zh