Skip to content

docs: add YAGNI and comment-density guidance - #44

Merged
cristim merged 4 commits into
mainfrom
docs/comment-density
Aug 3, 2026
Merged

docs: add YAGNI and comment-density guidance#44
cristim merged 4 commits into
mainfrom
docs/comment-density

Conversation

@cristim

@cristim cristim commented Aug 3, 2026

Copy link
Copy Markdown
Member

Closes #43

Why

A reviewer on a batch of agent-authored PRs: "wow, that was so overengineered i had a hard time getting through it." Two problems sat behind that sentence, and no rule covered either one.

Volume. For the same feature (a Puppet profile that builds a Go binary and installs it), the reviewer's version was 58 lines; the agent's was 343.

Comment bloat on top of it. Measured on added lines: 66% comment-to-code on the worst file (214 comment lines to 111 code lines), a four-line comment on a one-line config change, and three other PRs at 44%, 40% and 37%.

A line-by-line audit of that manifest is what shaped the guidance, because the honest result was not "the extra 285 lines were fat":

  • About a third was load-bearing and the shorter version would fail without it: a binary_name parameter a real caller needs, GOPRIVATE + submodule auth for private module fetches, timeout => 1800 where Puppet's exec default of 300s is wrong, running the build as the checkout owner, an ensure: absent guard.
  • The rest was real over-engineering with a recognisable shape: a parameter no caller overrides and one whose single caller always takes the default; ~15 lines of content-keyed build-stamp idempotence machinery for a second run that cannot happen (Packer runs Puppet once per image, then the toolchain is deleted); Pattern[...] constraints plus assert_type guards for the same values.

The build-stamp machinery is the instructive case: correct, carefully reasoned, and tested, and still waste, because the state it guarded was unreachable. That is what the section is built around. Reworked, the manifest went 343 -> 100 lines with every load-bearing behaviour intact, and comments 214 -> 20.

What changed

coding-standards.md gains two sections:

  • ## Simplicity & Scope (YAGNI) — leads with the test that the audit produced: not "is this correct?" or "could this ever happen?" but "does a current caller need this, and can this state be reached given the callers that exist?" Then: build only what a current caller needs; DRY but rule-of-three, since premature abstraction is over-engineering too and harder to undo than duplication; validate at trust boundaries and don't double up; prefer removing the hazard to defending against it (if a value needs validating because it reaches a shell, check whether it needs to reach a shell at all). Ends with a four-question pre-PR self-check and a closing caution that cutting means removing speculation, not behaviour — "shorter" is the symptom of getting this right, not the goal.
  • ## Comments — default to no comment; comment only where the WHY isn't deducible from the code; 1-2 lines, never paragraphs; a ~15% comment-to-code budget on added lines as a self-check; an explicit delete-on-sight list (restatements, rationale essays, review-round references, JSDoc restating the signature). Framing: rationale belongs in the PR description, the source carries only what a future editor needs in order not to break something. One good/bad example pair.

How the existing guidance was reconciled

This is the part worth reviewing, since the risk was bolting contradicting rules alongside what's already there.

  • CLAUDE.md §5 "Demand Elegance (Balanced)" opened with "pause and ask 'is there a more elegant way?'", which reads cold as an invitation to elaborate and plausibly contributed to the outcome above. Rather than adding a competing rule, §5 is clarified in place: the question becomes "is there a simpler way?", and elegance is defined as fewer moving parts, not more sophisticated ones — explicitly a prompt to remove machinery, never to add it. Section number and heading are unchanged, so the existing §5 cross-references still resolve.
  • "Simplicity First" absorbs YAGNI instead of gaining a neighbouring bullet saying nearly the same thing. Only one genuinely new core principle is added (comment sparingly), matching the shape of the existing entries.
  • The weak ## Documentation line ("Inline comments only for non-obvious logic") becomes a pointer to the new ## Comments section, leaving one source of truth instead of two overlapping statements.
  • git-workflow.md pre-commit review dimensions gain "Over-engineering & scope" and extend "Comment accuracy" to "Comment accuracy & density" — the gate previously checked whether comments had rotted but never whether there were too many. Without this the new standards would have had no enforcement point.

Scope

52 insertions, 6 deletions across three files. Kept deliberately tight: writing a treatise about not writing treatises would undercut the point.

Summary by CodeRabbit

  • Documentation
    • Added guidance on keeping changes simple, focused, and free from unnecessary abstractions.
    • Expanded recommendations for writing concise, accurate, and useful comments.
    • Added practical checks for validating scope, handling hazards, and reviewing documentation.
    • Updated the pre-commit checklist to include over-engineering, scope, and comment quality.
    • Clarified when to introduce abstractions and how to avoid speculative parameters and unnecessary machinery.

A reviewer on a batch of agent-authored PRs said the changes were
"so overengineered i had a hard time getting through it". Two problems
sat behind that: code doing more than any caller asked for, and comment
bloat burying it. For one feature the human version was 58 lines against
343; comment-to-code on added lines ran 37-66%, and a one-line config
change carried a four-line comment.

Neither was a rule violation, because no rule existed.

- coding-standards.md: add "Simplicity & Scope (YAGNI)" (build for the
  current caller, rule-of-three before abstracting, don't validate the
  impossible, pre-PR self-check) and "Comments" (default to none, 1-2
  lines, ~15% budget, explicit delete list, good/bad example).
- coding-standards.md: replace the weak inline-comments line under
  Documentation with a pointer, so there is one source of truth.
- CLAUDE.md: clarify §5 in place - elegance means fewer moving parts,
  not more sophisticated ones - since "is there a more elegant way?"
  reads cold as an invitation to elaborate. Fold YAGNI into the existing
  Simplicity First principle and add a comment-density principle.
- git-workflow.md: add over-engineering and comment density to the
  pre-commit review dimensions so the gate catches both.

Closes #43
@cristim cristim added documentation Improvements or additions to documentation triaged Item has been triaged type/docs Documentation impact/internal Team-internal only effort/s Hours severity/low Minor harm urgency/eventually No deadline priority/p3 Polish / idea / may never ship labels Aug 3, 2026
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 52 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b955e907-3c3f-4712-a03f-3a938007c70e

📥 Commits

Reviewing files that changed from the base of the PR and between 72ad4c2 and ce5de20.

📒 Files selected for processing (3)
  • CLAUDE.md
  • coding-standards.md
  • git-workflow.md
📝 Walkthrough

Walkthrough

The documentation now defines YAGNI, simpler implementation scope, limited validation and abstraction, concise comments, and pre-commit checks for over-engineering and comment density.

Changes

Engineering Guidance

Layer / File(s) Summary
Simplicity and YAGNI guidance
CLAUDE.md, coding-standards.md
The guidance favors fewer moving parts, current caller needs, limited abstraction, trust-boundary validation, and a pre-PR self-check.
Comment and review checklist guidance
coding-standards.md, git-workflow.md
The documentation defines concise comments, points inline documentation to the Comments section, and adds checks for scope, over-engineering, comment accuracy, and comment density.

Estimated code review effort: 1 (Trivial) | ~5 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the PR's main change: adding YAGNI and comment-density guidance.
Linked Issues check ✅ Passed The PR adds the YAGNI, simplicity, comment-density, and review-gate guidance required by [#43].
Out of Scope Changes check ✅ Passed All changes are documentation updates directly aligned with the scope and requirements in [#43].
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch docs/comment-density

Comment @coderabbitai help to get the list of available commands.

…correcting

A line-by-line audit of the 343-line manifest against the reviewer's
58-line one showed roughly a third of the extra code was load-bearing,
not fat: a binary_name parameter a real caller needs, GOPRIVATE and
submodule auth for private module fetches, a timeout the platform
default gets wrong, and an ensure => absent guard.

That nuance is what makes the rule usable, so state it:

- The test is not "is this correct?" or "could this ever happen?" but
  "does a current caller need this, and can this state be reached given
  the callers that exist?" The clearest case in that batch was ~15 lines
  of build-stamp idempotence machinery that was correct, reasoned and
  tested, and still waste, because Packer runs the code once per image
  and then discards the machine.
- Prefer removing the hazard to defending against it: collapsing one
  shell-interpolated onlyif into a constant string deleted the injection
  path and made the surrounding validation unnecessary.
- Don't double up validation (a type constraint and a runtime assert for
  the same value).
- Closing caution so this doesn't read as "shorter is better": cut
  speculation, not behaviour.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
coding-standards.md (1)

164-167: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add exceptions for required documentation and stable constraint references.

The “Delete on sight” list includes past-bug references and JSDoc/docstrings, but this section permits comments for external-bug workarounds and the Documentation section requires API docs to stay synchronized. Retain concise issue or CVE references and semantic API documentation when they explain a constraint. Delete only redundant restatements and review-history narrative.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@coding-standards.md` around lines 164 - 167, Update the “Delete on sight”
guidance in coding-standards.md to explicitly preserve concise external-bug or
CVE references when documenting workarounds, and retain semantic
JSDoc/docstrings required by the Documentation section for API contracts.
Continue removing only redundant type restatements and review-history narrative.
CLAUDE.md (1)

185-185: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Align the simplicity heuristics across both documents.

The guidance should reject unnecessary machinery, not justified abstractions or readable implementations.

  • CLAUDE.md#L185-L185: qualify the rule so an added concept is acceptable when it removes duplication, clarifies an invariant, or preserves a boundary contract.
  • coding-standards.md#L47-L48: make the rule-of-three a consideration, not a mandatory abstraction threshold.
  • coding-standards.md#L52-L56: replace fixed consumer and line-count tests with checks for current need, correctness, clarity, and total complexity.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@CLAUDE.md` at line 185, Align the simplicity guidance across all three sites:
in CLAUDE.md lines 185-185, qualify the rule so added concepts are acceptable
when they remove duplication, clarify an invariant, or preserve a boundary
contract; in coding-standards.md lines 47-48, make the rule-of-three a
consideration rather than a mandatory abstraction threshold; and in
coding-standards.md lines 52-56, replace fixed consumer and line-count tests
with evaluation of current need, correctness, clarity, and total complexity.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@coding-standards.md`:
- Line 49: Revise the “Don't validate the impossible” guidance to distinguish
redundant internal checks from invariant enforcement: retain validation at trust
boundaries, but require explicit assertions or errors when internal invariants
are violated. Limit the recommendation to checks guaranteed by a maintained
contract, rather than treating all defensive handling of unreachable states as
dead code.
- Around line 169-180: Update both context.WithTimeout examples to call defer
cancel() immediately after creating the timeout context, preserving the existing
comments and timeout behavior while ensuring each context’s resources are
released when its operation completes.

---

Nitpick comments:
In `@CLAUDE.md`:
- Line 185: Align the simplicity guidance across all three sites: in CLAUDE.md
lines 185-185, qualify the rule so added concepts are acceptable when they
remove duplication, clarify an invariant, or preserve a boundary contract; in
coding-standards.md lines 47-48, make the rule-of-three a consideration rather
than a mandatory abstraction threshold; and in coding-standards.md lines 52-56,
replace fixed consumer and line-count tests with evaluation of current need,
correctness, clarity, and total complexity.

In `@coding-standards.md`:
- Around line 164-167: Update the “Delete on sight” guidance in
coding-standards.md to explicitly preserve concise external-bug or CVE
references when documenting workarounds, and retain semantic JSDoc/docstrings
required by the Documentation section for API contracts. Continue removing only
redundant type restatements and review-history narrative.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b10e0b3d-fbe1-42a2-a770-0f97ff780e9b

📥 Commits

Reviewing files that changed from the base of the PR and between 72ad4c2 and 598f290.

📒 Files selected for processing (3)
  • CLAUDE.md
  • coding-standards.md
  • git-workflow.md

Comment thread coding-standards.md Outdated
Comment thread coding-standards.md
@cristim

cristim commented Aug 3, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

The two context.WithTimeout examples left `cancel` unused, which does not
compile and leaks the timer; add `defer cancel()` to both.

"Delete on sight" listed "past bugs" while the bullet above sanctions a
comment for an external-bug workaround. Say "our own past bugs" and note
that the sanctioned case carries an upstream issue or CVE link, so the
two rules no longer read as contradicting each other.
@cristim

cristim commented Aug 3, 2026

Copy link
Copy Markdown
Member Author

Triage of the review, thanks @coderabbitai:

Addressed in 08e6ede

  • defer cancel() added to both context.WithTimeout examples (they would not have compiled as written).
  • "Delete on sight" nitpick, external-bug half: the list said "past bugs" while the bullet above sanctions a comment for an external-bug workaround. Now "our own past bugs", and the sanctioned case explicitly says to link the upstream issue or CVE.

Dismissed

  • "Delete on sight", JSDoc half: the entry is already scoped to "JSDoc/docstrings restating types the signature already gives". Semantic API docs are not covered by it and the Documentation section still requires them, so there is nothing to reconcile.
  • "Align the simplicity heuristics" (qualify the added-concept rule, soften rule-of-three to a consideration, drop the line-count and consumer tests): this reverses the change rather than refining it. The PR exists because "elegance" was being read as an invitation to add machinery, so the whole point of the §5 wording is that an added concept is a cost that has to earn itself. The counterweight you are asking for is already in the section: "Cut speculation, not behaviour. A parameter a real caller sets, a timeout the platform's default gets wrong, the auth config a private dependency needs: all load-bearing, however many lines they add." The self-check items are deliberately blunt prompts, not gates, and softening every one of them into "evaluate current need, correctness, clarity and total complexity" would leave guidance that no longer decides anything. Also declining on scope grounds: this is a PR about not over-writing, and the fix would grow it substantially.

@cristim

cristim commented Aug 3, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.


Your included review limit is currently reached under our Fair Usage Limits Policy. Your recent PR review activity is in the 95th percentile or higher among CodeRabbit users, so adaptive limits apply. This review may still proceed through usage-based billing if eligible. Your next included review will be available in 14 minutes.

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

git show --stat --oneline 08e6ede
git show --format=fuller --find-renames --find-copies 08e6ede -- \
  CLAUDE.md coding-standards.md git-workflow.md

printf '\n--- current occurrences and context ---\n'
rg -n -i -C 8 \
  'context\.WithTimeout|defer cancel|Delete on sight|our own past bugs|external.*(issue|CVE)|JSDoc|docstrings|Rule of three|rule of three|added concept|Cut speculation|current caller|consumer|lines' \
  CLAUDE.md coding-standards.md git-workflow.md

Length of output: 39085


@cristim Confirmed.

08e6ede adds defer cancel() to both context.WithTimeout examples. It also removes the conflict between the external-bug workaround rule and the “Delete on sight” list.

I withdraw the JSDoc/docstring finding. The rule is limited to type-restating documentation. The Documentation section still requires semantic API documentation.

I also accept the decision on the simplicity heuristics. The section states that real caller requirements and load-bearing behavior remain valid, regardless of line count. The firm self-check prompts are consistent with the stated purpose of this PR.


✏️ Learnings added
Learnt from: cristim
URL: https://github.com/LeanerCloud/dotclaude/pull/44

Timestamp: 2026-08-03T14:59:18.202Z
Learning: In `coding-standards.md`, the “Delete on sight” rule for JSDoc/docstrings applies only when they restate type information already supplied by the signature. Semantic API documentation remains required by the Documentation section.

Learnt from: cristim
URL: https://github.com/LeanerCloud/dotclaude/pull/44

Timestamp: 2026-08-03T14:59:18.202Z
Learning: In `coding-standards.md`, the “Simplicity & Scope (YAGNI)” self-check uses deliberately firm prompts to prevent speculative machinery. The section explicitly exempts load-bearing behavior required by real current callers, platform constraints, or private dependencies.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

You are interacting with an AI system.

@cristim

cristim commented Aug 3, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@coding-standards.md`:
- Line 172: Update the “Delete on sight” bullet in coding-standards.md to escape
or inline-code the “<date>” placeholder so Markdown renders it visibly as text
rather than interpreting it as an HTML tag.

In `@git-workflow.md`:
- Around line 47-48: Align the review loop marked “NO EXCEPTIONS” with the skip
policy in CLAUDE.md: define the trivial/mechanical-edit exception once, or
restrict the loop to non-trivial or substantial changes. Keep the existing
checks for changes that remain in scope and update the accompanying comment so
it accurately describes the resulting policy.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f8ef1662-d209-48e2-8a00-c5f831f2c3d6

📥 Commits

Reviewing files that changed from the base of the PR and between 72ad4c2 and 08e6ede.

📒 Files selected for processing (3)
  • CLAUDE.md
  • coding-standards.md
  • git-workflow.md

Comment thread coding-standards.md Outdated
Comment thread git-workflow.md
GitHub's Markdown strips `<date>` as an unknown HTML tag, so the bullet
rendered as `as of ""` and the placeholder disappeared. Wrap the phrase in
backticks so it renders literally.
@cristim

cristim commented Aug 3, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.


Your included review limit is currently reached under our Fair Usage Limits Policy. Your recent PR review activity is in the 95th percentile or higher among CodeRabbit users, so adaptive limits apply. This review may still proceed through usage-based billing if eligible. Your next included review will be available in 49 minutes.

@cristim

cristim commented Aug 3, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.


Your included review limit is currently reached under our Fair Usage Limits Policy. Your recent PR review activity is in the 95th percentile or higher among CodeRabbit users, so adaptive limits apply. This review may still proceed through usage-based billing if eligible. Your next included review will be available in 52 minutes.

@cristim
cristim merged commit 0f4d576 into main Aug 3, 2026
1 check passed
@cristim
cristim deleted the docs/comment-density branch August 3, 2026 21:19
cristim added a commit that referenced this pull request Aug 5, 2026
)

* docs: add refactor-verification guidance and the worktree hook trap

The YAGNI section added in #44 says what to cut but nothing about proving
the cut preserved behaviour, which leaves "delete aggressively" as advice
without a safety net.

Adds a "Verifying a Refactor" section covering subtractive-only edits,
byte-comparing every generated artifact rather than trusting tests, carrying
a protected list into the work, never removing security assertions on your
own judgement, and treating "nothing worth removing" as a complete answer.

Also records that git hooks silently do not run in a worktree when
core.hooksPath points at an install-generated directory, which matters
because worktrees are the default for non-trivial work.

* docs: make over-engineering the sixth review dimension

The YAGNI guidance only bit when someone remembered to look for it. Adding
it to the review dimensions puts it in the plan-review gate, the post-
implementation review, the local review loop and the pre-commit loop, so
pruning happens on every change rather than as an occasional cleanup.

Flagged as an adversarial check on purpose: the author's local justification
for a piece of machinery almost always holds up, so the reviewer has to ask
what the calling system actually does instead.

Updates the five-dimension references across git-workflow.md and the two
autopilot prompts to match.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation effort/s Hours impact/internal Team-internal only priority/p3 Polish / idea / may never ship severity/low Minor harm triaged Item has been triaged type/docs Documentation urgency/eventually No deadline

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docs: no guidance against over-engineering or comment bloat (58-line feature shipped as 343 lines, 40-66% comments)

1 participant