Comment style
A comment is the last resort. Work down this ladder, and write prose only
when all four rungs fail. This applies to the Python in vinowhisper/ and
the Rust in tray/, gui/ and settings/.
-
Extract it. Logic that a comment explains belongs in a function with a domain name. Arithmetic spelled out in a comment belongs in named constants. A coercion that is explained twice belongs in one named helper.
# Beforeif len(samples) < 16000 * 0.3: # 300 ms at 16 kHz# Afterif len(samples) < MIN_SPEECH_SAMPLES: -
Name it. A comment that labels a block (
// 2. read the bundle) means the block wants to be a function. Sentinels get names too: writeUSE_APP_DEFAULT, notNone # = the app's default. -
Pin it with a test pair. A comment that states a business rule is a rule nothing enforces. Write one test inside the boundary and one outside, named after the rule, instead of writing
# exactly at the limit is fine. The pair is the point: it fails the day someone moves the limit. In a test, a comment that labels the next few asserts is the same smell. Split those asserts into their own test, named after what the comment said. -
Pin cross-boundary rules with an end-to-end test. The CLI contract, the server’s HTTP API, the tray/server socket protocol, what the settings files round-trip to and what
install.shwrites belong in a test that crosses that boundary, not in a paragraph. -
Only then, prose. Hidden constraints, upstream bugs, protocol requirements, incident history that still constrains the code. State the constraint, not its biography: “spawn the child from the main thread:
PR_SET_PDEATHSIGfires when the spawning thread exits” is enough without the story of how we found out. Measured claims carry a date. Longer rationale goes in the matchingdocs/page.
Linking the test from the code
Section titled “Linking the test from the code”When rung 3 or 4 replaced a comment, the code it governs says which test pins the rule, always with the same phrase:
// Under the limit is kept; at it is dropped (pinned by// `tests::keeps_a_session_just_under_the_limit`).# (pinned by `test_stitch.py::test_a_repeat_at_the_seam_is_dropped`)Rust cites `tests::name` (the file’s own test module, or its
<file>/tests.rs) or `module::tests::name`, resolved inside the same
crate. Python cites `test_file.py::test_name` under tests/.
rustdoc can’t link to #[test] functions, so these are code spans, not
links. Two checks keep them honest, both part of the “Doc Links” CI job:
settings/tests/doc_links.rs for the three crates and
tests/test_doc_links.py for the Python. Each fails on a citation with no
such test.
Exempt
Section titled “Exempt”///and//!docs on items, which say what an item is and how to call it. They follow the same “constraint, not biography” rule, and a doc that restates the signature goes.characterization:docstrings ontest_characterization_*tests (seeCLAUDE.md).// SAFETY:comments onunsafe,#[allow]and# noqa/# type: ignorereasons, and coverage pragmas.