Coding
Making Changes
Note: These rules are defaults; deviate only when you can state what following the rule would cost here.
- DRY: a string, a threshold, a supported-values list has one authoritative home, easy to change/update/extend.
- Do not overfit: Avoid overfitting solutions to problems in this chat. Think bigger.
- Separation of Concerns & Extendable Components: Insist on separation of concerns.
- Duplication over the wrong abstraction governs structure: tolerate two similar blocks until the shared concept is obvious (rule of three); a helper/component that needs a
mode flag to serve
both callers is the wrong abstraction.
- Extend along the promised axis: at three cases the axis is promised (rule of three); shape code to make the fourth easy to add, without overfitting to just today's use-cases.
- Don't name a general structure after its first occupant: once something is a shared slot or grouping, name it for the axis it opens — not for today's only member. Specificity belongs on the
leaves.
- Tidy/Refactor separate from feature work: an opportunistic refactor is in its own commit. Each stays reviewable.
Code Comments
Guiding Principles:
- Write for the stranger who understands the purpose of the project: a comment must hold
for a reader with only the file (and its project); with no access to this conversation, no
contextual awareness of how the project evolved, no memory of the task that produced it. A
comment that echoes this session's instructions fails (e.g.
// Doing X (no Y) where Y is
something only this conversation knows).
- Write to a reader who isn't aware of our chats, and does not include explanations or justifications based on our current conversation, or from our chat.
- STOP Making code comments that make sense only in the context of the chat that overfit to our current conversation.
- DO Not add comments about delta that are not with main. A comment to explain evolution of something between two commit of the same branch is redundant and won't make sense once commits are
squashed.
- Describe the steady state, not the delta:
// reads users_v2, not // migrated from users_v1. Git records the transition, and delta comments become lies the moment it
completes. A transition that must live in the code is a TODO with an end condition, never
loose prose. Same for deletions and moves: git history is the record; leave no moved to X
breadcrumb behind.
- WHY only as protection: explain how we got here only when it stops the stranger from a wrong move, like "fixing" a deliberate choice, removing a needed workaround, or mistaking a cut corner for
naivety. The next three principles are its instances.
- Mention a rejected alternative only as a warning: keep
// not cached: results are user-specific because it stops a stranger from "fixing" it; drop // using native Map (no lodash) because
that avoidance only answers this session's instruction.
- Workarounds cite their cause:
// workaround: SDK drops keepalive on h2, see github.com/x/y#456. The link is the stranger's only way to check it's still needed.
- A cut corner names its ceiling:
// good enough: O(n²) scan; revisit past ~1k rules states the limit and the upgrade trigger, so the stranger can tell
deliberate simplicity from naivety. Only for real corners with a known ceiling;
trivial simplifications need no plaque.
- A TODO names what ends it: a ticket, date, or event, as in
// TODO(PROJ-123): drop fallback after v2 ships. Same for any "temporary"/"for now" claim; without an end condition it's permanent.
Bare // TODO: clean up is a wish that sediments.
- Avoid enumeration; name the set, not its members:
// sanitize PII fields, not // sanitize email, phone, SSN, address. The criterion stays true
as the set grows; the list reads as complete and rots. When examples aid
clarity, mark them illustrative: (e.g. email, SSN).
Docs
Docs follow the Code Comments principles; the stranger is the reader. Especially: name the set, not its members; and don't hard-code today's specifics (counts, versions, file lists) that rot as the
project moves.
1---2name: coding3description: The user's coding and docs conventions and taste. Load FIRST, at the start of any task that touches code or docs.4license: MIT5---67# Coding89## Making Changes1011**Note:** These rules are defaults; deviate only when you can state what following the rule would cost here.1213- **DRY**: a string, a threshold, a supported-values list has one authoritative home, easy to change/update/extend.14- **Do not overfit**: Avoid overfitting solutions to problems in this chat. Think bigger.15- **Separation of Concerns & Extendable Components**: Insist on separation of concerns.16- **Duplication over the wrong abstraction governs structure**: tolerate two similar blocks until the shared concept is obvious (rule of three); a helper/component that needs a `mode` flag to serve17 both callers is the wrong abstraction.18- **Extend along the promised axis**: at three cases the axis is promised (rule of three); shape code to make the fourth easy to add, without overfitting to just today's use-cases.19- **Don't name a general structure after its first occupant**: once something is a shared slot or grouping, name it for the axis it opens — not for today's only member. Specificity belongs on the20 leaves.21- **Tidy/Refactor separate from feature work**: an opportunistic refactor is in its own commit. Each stays reviewable.2223## Code Comments2425Guiding Principles:26271. **Write for the stranger who understands the purpose of the project**: a comment must hold28 for a reader with only the file (and its project); with no access to this conversation, no29 contextual awareness of how the project evolved, no memory of the task that produced it. A30 comment that echoes this session's instructions fails (e.g. `// Doing X (no Y)` where Y is31 something only this conversation knows).322. Write to a reader who isn't aware of our chats, and does not include explanations or justifications based on our current conversation, or from our chat.332. STOP Making code comments that make sense only in the context of the chat that overfit to our current conversation.343. DO Not add comments about delta that are not with main. A comment to explain evolution of something between two commit of the same branch is redundant and won't make sense once commits are35 squashed.362. **Describe the steady state, not the delta**: `// reads users_v2`, not `// migrated from37 users_v1`. Git records the transition, and delta comments become lies the moment it38 completes. A transition that must live in the code is a TODO with an end condition, never39 loose prose. Same for deletions and moves: git history is the record; leave no `moved to X`40 breadcrumb behind.413. **WHY only as protection**: explain how we got here only when it stops the stranger from a wrong move, like "fixing" a deliberate choice, removing a needed workaround, or mistaking a cut corner for42 naivety. The next three principles are its instances.434. **Mention a rejected alternative only as a warning**: keep `// not cached: results are user-specific` because it stops a stranger from "fixing" it; drop `// using native Map (no lodash)` because44 that avoidance only answers this session's instruction.455. **Workarounds cite their cause**: `// workaround: SDK drops keepalive on h2, see github.com/x/y#456`. The link is the stranger's only way to check it's still needed.466. **A cut corner names its ceiling**: `// good enough: O(n²) scan; revisit past47 ~1k rules` states the limit and the upgrade trigger, so the stranger can tell48 deliberate simplicity from naivety. Only for real corners with a known ceiling;49 trivial simplifications need no plaque.507. **A TODO names what ends it**: a ticket, date, or event, as in `// TODO(PROJ-123): drop fallback after v2 ships`. Same for any "temporary"/"for now" claim; without an end condition it's permanent.51 Bare `// TODO: clean up` is a wish that sediments.528. **Avoid enumeration; name the set, not its members**: `// sanitize PII53 fields`, not `// sanitize email, phone, SSN, address`. The criterion stays true54 as the set grows; the list reads as complete and rots. When examples aid55 clarity, mark them illustrative: `(e.g. email, SSN)`.5657## Docs5859Docs follow the Code Comments principles; the stranger is the reader. Especially: name the set, not its members; and don't hard-code today's specifics (counts, versions, file lists) that rot as the60project moves.