Skip to content

Commit a33f690

Browse files
committed
chore(doc/reference): documentation for consistency and clarity
1 parent a393828 commit a33f690

8 files changed

Lines changed: 310 additions & 310 deletions

doc/reference/SIMPLE-DESIGN.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
# Kent Beck's Four Rules of Simple Design
1+
# Kent Beck's four rules of simple design
22

3-
These rules provide objective criteria for evaluating code design. They're in priority orderhigher rules take precedence over lower ones when they conflict.
3+
These rules provide objective criteria for evaluating code design. They're in priority order: higher rules take precedence over lower ones when they conflict.
44

5-
## Rule 1: Passes the Tests
5+
## Rule 1: Passes the tests
66

77
**The code must work as intended.**
88

99
- All functionality proven through automated tests
1010
- Nothing else matters if the system behaves incorrectly
1111
- Tests provide confidence to refactor and improve design
12-
- Avoid tests that only verify implementation details—tests should assert correct behavior
12+
- Avoid tests that only verify implementation details. Tests should assert correct behavior
1313

14-
**Example**: Before optimizing SQL parsing or parameter binding logic, ensure comprehensive tests prove correctness across all supported SQLite data types and edge cases.
14+
**Example**: Before optimizing SQL parsing or parameter binding logic, ensure tests prove correctness across all supported SQLite data types and edge cases.
1515

16-
**Pitfall**: Don't skip tests for "simple" changesSQLite has countless edge cases across different data types, encoding scenarios, and concurrent access patterns.
16+
**Pitfall**: Don't skip tests for "simple" changes. SQLite has countless edge cases across different data types, encoding scenarios, and concurrent access patterns.
1717

18-
## Rule 2: Reveals Intention
18+
## Rule 2: Reveals intention
1919

2020
**Code should clearly express what it does and why.**
2121

2222
- Use descriptive names for variables, functions, and types
2323
- Structure code to match the problem domain
2424
- Prioritize readability for future maintainers
2525

26-
## Rule 3: No Duplication
26+
## Rule 3: No duplication
2727

2828
**Eliminate repeated logic and knowledge.**
2929

@@ -33,9 +33,9 @@ These rules provide objective criteria for evaluating code design. They're in pr
3333

3434
**Example**: Instead of duplicating SQLite type conversion logic across DatabaseSync and StatementSync classes, extract the conversion functions to a shared utility module.
3535

36-
**Pitfall**: Don't create premature abstractions—sometimes temporary duplication is acceptable while understanding emerges, especially when porting code from Node.js internals.
36+
**Pitfall**: Don't create premature abstractions. Sometimes temporary duplication is acceptable while understanding emerges, especially when porting code from Node.js internals.
3737

38-
## Rule 4: Fewest Elements
38+
## Rule 4: Fewest elements
3939

4040
**Remove anything that doesn't serve the first three rules.**
4141

@@ -45,7 +45,7 @@ These rules provide objective criteria for evaluating code design. They're in pr
4545

4646
**Example**: Don't build a complex caching layer for prepared statements until profiling shows it's actually a bottleneck, and don't create wrapper abstractions for SQLite features until multiple use cases demonstrate the need.
4747

48-
**Pitfall**: Don't over-apply this rule—necessary complexity is still necessary. Native code interop and memory management require inherent complexity.
48+
**Pitfall**: Don't over-apply this rule. Necessary complexity is still necessary. Native code interop and memory management require inherent complexity.
4949

5050
## Rule 5: No bogus guardrails or defaults
5151

@@ -55,19 +55,19 @@ When key assumptions that your code relies upon to work appear to be broken, fai
5555
- If you are fairly certain data should always exist, assume it does, rather than producing code with unnecessary guardrails or existence checks (esp. if such checks might mislead other programmers)
5656
- Never use 'defaults' as a result of errors, either for users, or downstream callers.
5757

58-
## Priority and Conflicts
58+
## Priority and conflicts
5959

6060
**When rules conflict, higher numbers win:**
6161

6262
- Working code (Rule 1) beats everything
6363
- Clear names (Rule 2) and no duplication (Rule 3) often reinforce each other
64-
- The "duplication vs clarity" debate misses the point—both improve together over time
64+
- The "duplication vs clarity" debate misses the point. Both improve together over time
6565

6666
**Common conflict**: During refactoring, you might temporarily duplicate code to pass tests, then eliminate duplication while improving names.
6767

6868
**Exception**: In test code, empathy for readers sometimes trumps technical purity.
6969

70-
## Quick Reference
70+
## Quick reference
7171

7272
Use this checklist during code review:
7373

doc/reference/TPP-GUIDE.md

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Technical Project Plan (TPP) Guide
1+
# Technical project plan (TPP) guide
22

33
## Purpose
44

5-
A TPP transfers expertise, not just instructions. A great TPP lets another engineer complete the work without asking questionseven if the code changed since you wrote it.
5+
A TPP transfers expertise, not just instructions. A great TPP lets another engineer complete the work without asking questions, even if the code changed since you wrote it.
66

77
**The golden rule**: If an implementer fails because context was missing from your TPP, that's your failure, not theirs.
88

9-
## Required Reading
9+
## Required reading
1010

1111
Before writing any TPP, read and incorporate:
1212

@@ -15,9 +15,9 @@ Before writing any TPP, read and incorporate:
1515

1616
These are not optional. TPPs that ignore them will be rejected.
1717

18-
## TPP Structure
18+
## TPP structure
1919

20-
### Part 1: Define Success (5 minutes max)
20+
### Part 1: Define success (5 minutes max)
2121

2222
Write one clear sentence for each:
2323

@@ -26,7 +26,7 @@ Write one clear sentence for each:
2626
**Why it matters**: Breaks compatibility with node:sqlite which returns []
2727
**Solution**: Match node:sqlite behavior in StatementSync::All()
2828
**Success test**: `npm t -- --grep "empty result"`
29-
**Key constraint**: Must match node:sqlite exactly—test against Node.js built-in
29+
**Key constraint**: Must match node:sqlite exactly. Test against Node.js built-in
3030
```
3131

3232
This is your North Star. Implementation details may change; the user need stays constant.
@@ -40,7 +40,7 @@ This is your North Star. Implementation details may change; the user need stays
4040
**Fix approach**: Add null check matching node_sqlite.cc:892
4141
```
4242

43-
#### When TDD Isn't Possible
43+
#### When TDD isn't possible
4444

4545
Some bugs can't be reproduced in tests:
4646

@@ -63,11 +63,11 @@ For these, document explicitly:
6363

6464
Don't pretend a test covers something it doesn't. Be explicit about what's validated and what isn't.
6565

66-
### Part 2: Share Your Expertise
66+
### Part 2: Share your expertise
6767

68-
This section prevents surprises. Skip it for straightforward changes—document only what's non-obvious.
68+
This section prevents surprises. Skip it for straightforward changes. Document only what's non-obvious.
6969

70-
#### A. Find the Patterns
70+
#### A. Find the patterns
7171

7272
Show what already works similarly:
7373

@@ -83,9 +83,9 @@ ls src/upstream/
8383
Document what you find:
8484

8585
- "Copy pattern from `src/sqlite_impl.cpp:DatabaseSync::Exec` for statement execution"
86-
- "NEVER edit `src/upstream/*`these files are synced from Node.js"
86+
- "NEVER edit `src/upstream/*` (these files are synced from Node.js)"
8787

88-
#### B. Document the Landmines
88+
#### B. Document the landmines
8989

9090
Share what will break and why:
9191

@@ -97,13 +97,13 @@ npm t 2>&1 | grep -i "parameter" # Tests that catch mistakes
9797

9898
Document the dangers:
9999

100-
- "N-API's `IsBuffer()` returns true for ALL ArrayBufferView types—check `IsDataView()` FIRST"
101-
- "Cannot use `Napi::Reference` from SQLite callbacks—store POD types only"
102-
- "Windows requires retry logic for temp file cleanup—use `useTempDir()` utility"
100+
- "N-API's `IsBuffer()` returns true for ALL ArrayBufferView types. Check `IsDataView()` FIRST"
101+
- "Cannot use `Napi::Reference` from SQLite callbacks. Store POD types only"
102+
- "Windows requires retry logic for temp file cleanup. Use `useTempDir()` utility"
103103

104-
**Apply SIMPLE-DESIGN.md Rule 2 (Reveals Intention)**: Don't just say "this breaks"—explain why it was designed this way.
104+
**Apply SIMPLE-DESIGN.md Rule 2 (Reveals Intention)**: Don't just say "this breaks". Explain why it was designed this way.
105105

106-
#### C. Plan for Change
106+
#### C. Plan for change
107107

108108
If architecture changes, how should the implementer adapt?
109109

@@ -115,7 +115,7 @@ If BindValue() was refactored:
115115
3. Core goal: JS values → SQLite-bound parameters
116116
```
117117

118-
### Part 3: Define Clear Tasks
118+
### Part 3: Define clear tasks
119119

120120
Each task needs:
121121

@@ -146,9 +146,9 @@ Each task needs:
146146
- [ ] Old code removed: No workarounds remain (Rule 4 - fewest elements)
147147
```
148148

149-
## node-sqlite Specific Concerns
149+
## node-sqlite specific concerns
150150

151-
### API Compatibility Is Non-Negotiable
151+
### API compatibility is non-negotiable
152152

153153
Every feature must match `node:sqlite` exactly:
154154

@@ -163,7 +163,7 @@ const ourResult = new OurDB(":memory:").prepare("SELECT 1").get();
163163
expect(ourResult).toEqual(nodeResult);
164164
```
165165

166-
### Upstream Files Are Sacred
166+
### Upstream files are sacred
167167

168168
Never modify files in `src/upstream/`. They're synced from Node.js.
169169

@@ -175,7 +175,7 @@ ls src/upstream/
175175
# Reference: third-party/node/src/node_sqlite.cc
176176
```
177177

178-
### N-API Gotchas to Document
178+
### N-API gotchas to document
179179

180180
When your task involves native code, document these traps:
181181

@@ -186,24 +186,24 @@ When your task involves native code, document these traps:
186186
| Aggregate state | Memory corruption | JSON serialize complex objects |
187187
| Resource cleanup | Jest hangs | Close all databases in afterEach |
188188

189-
### Platform-Specific Failures
189+
### Platform-specific failures
190190

191191
Document when behavior varies:
192192

193193
```markdown
194-
**Windows**: File locks persist longer—use retry logic in cleanup
195-
**Alpine ARM64**: 10x slower in CI—use `getTestTimeout()` for timing tests
196-
**macOS**: VM performance varies—avoid exact timing assertions
194+
**Windows**: File locks persist longer. Use retry logic in cleanup
195+
**Alpine ARM64**: 10x slower in CI. Use `getTestTimeout()` for timing tests
196+
**macOS**: VM performance varies. Avoid exact timing assertions
197197
```
198198

199-
## Anti-Patterns to Avoid
199+
## Anti-patterns to avoid
200200

201-
### "It Works" Without Proof
201+
### "It works" without proof
202202

203203
Bad: "I tested it and it works"
204204
Good: "Test passes: `npm t -- --grep 'specific test name'`"
205205

206-
### Shelf-ware Code
206+
### Shelf-ware code
207207

208208
Implementation exists but nothing uses it. Every feature needs integration proof:
209209

@@ -212,25 +212,25 @@ Implementation exists but nothing uses it. Every feature needs integration proof
212212
grep -r "newFunction" src/ test/ # Must appear in both
213213
```
214214

215-
### The 95% Trap
215+
### The 95% trap
216216

217-
"Just needs cleanup" = 50% more work. Tasks are complete or incomplete—no percentages.
217+
"Just needs cleanup" = 50% more work. Tasks are complete or incomplete. No percentages.
218218

219-
### Bogus Guardrails
219+
### Bogus guardrails
220220

221221
Per [SIMPLE-DESIGN.md](./SIMPLE-DESIGN.md) Rule 5: Don't add defensive code for impossible cases. If assumptions are violated, fail visibly.
222222

223-
### Testing the Wrong Thing
223+
### Testing the wrong thing
224224

225225
Bad: "Added test for NULL handling" (but test exercises `SQLITE_NULL` type, not NULL pointer from extraction failure)
226226

227-
Good: "Added regression test for TEXT/BLOB paths. The actual NULL-pointer edge case is untestable—validated via code review against `aggregate_function.cpp:515-530`"
227+
Good: "Added regression test for TEXT/BLOB paths. The actual NULL-pointer edge case is untestable. Validated via code review against `aggregate_function.cpp:515-530`"
228228

229229
Be precise about what your test actually validates vs. what remains validated only by code review.
230230

231-
## Validation Requirements
231+
## Validation requirements
232232

233-
### Required Evidence Types
233+
### Required evidence types
234234

235235
Every checkbox needs proof another engineer can verify:
236236

@@ -239,7 +239,7 @@ Every checkbox needs proof another engineer can verify:
239239
- **Integration proof**: `grep` commands showing production usage
240240
- **Behavior comparison**: Test output against node:sqlite
241241

242-
### Completeness Validation
242+
### Completeness validation
243243

244244
For fixes that apply to multiple locations, the TPP must include a scope check:
245245

@@ -254,7 +254,7 @@ A fix for one instance that misses others is incomplete. Document:
254254
- Which files contain them
255255
- Validation that ALL were addressed
256256

257-
### Definition of Complete
257+
### Definition of complete
258258

259259
A task is complete when:
260260

@@ -264,7 +264,7 @@ A task is complete when:
264264
4. All validation commands pass
265265
5. `npm t` shows no regressions
266266

267-
### Common Over-Selling Patterns
267+
### Common over-selling patterns
268268

269269
Do NOT mark complete if:
270270

@@ -273,7 +273,7 @@ Do NOT mark complete if:
273273
- "Ready for review" but `npm run lint` fails
274274
- "Feature complete" but old path still active
275275

276-
## Quality Checklist
276+
## Quality checklist
277277

278278
Before marking your TPP ready:
279279

@@ -282,41 +282,41 @@ Before marking your TPP ready:
282282
- [ ] Documented at least one "learned the hard way" lesson
283283
- [ ] Each task has verifiable success command
284284
- [ ] Explained how to adapt if code was refactored
285-
- [ ] Bug fixes start with failing test ([TDD.md](./TDD.md))or document why TDD isn't possible
285+
- [ ] Bug fixes start with failing test ([TDD.md](./TDD.md)), or document why TDD isn't possible
286286
- [ ] Code follows Four Rules ([SIMPLE-DESIGN.md](./SIMPLE-DESIGN.md))
287287
- [ ] API compatibility with node:sqlite verified
288288
- [ ] If fix applies to multiple locations, included grep to find ALL instances
289289
- [ ] Test descriptions clarify what IS and ISN'T covered
290290

291-
## The Ultimate Test
291+
## The ultimate test
292292

293-
Hand this TPP to someone unfamiliar with the codebase. If they can implement the solution without asking questionseven if the code was refactoredyou've written an excellent TPP.
293+
Hand this TPP to someone unfamiliar with the codebase. If they can implement the solution without asking questions, even if the code was refactored, you've written an excellent TPP.
294294

295-
## TPP Template
295+
## TPP template
296296

297297
Copy this structure for new TPPs--but omit sections that aren't relevant or helpful.
298298

299299
```markdown
300300
# TPP: [Specific Project Name]
301301

302-
## Goal Definition
302+
## Goal definition
303303

304-
- **What Success Looks Like**: [1 sentence]
305-
- **Core Problem**: [1 sentence]
306-
- **Key Constraints**: [1 sentenceinclude API compatibility requirement]
307-
- **Success Validation**: [1 sentenceinclude test command]
304+
- **What success looks like**: [1 sentence]
305+
- **Core problem**: [1 sentence]
306+
- **Key constraints**: [1 sentence, include API compatibility requirement]
307+
- **Success validation**: [1 sentence, include test command]
308308

309-
## Context Research
309+
## Context research
310310

311-
### Existing Patterns
311+
### Existing patterns
312312

313313
[What similar code exists? Where?]
314314

315315
### Landmines
316316

317317
[What breaks easily? N-API gotchas? Platform issues?]
318318

319-
### node:sqlite Behavior
319+
### node:sqlite behavior
320320

321321
[What does the built-in do? Reference node_sqlite.cc lines]
322322

@@ -345,8 +345,8 @@ As additional research and implementation details are completed, reconsider thes
345345

346346
**What this test validates** (be precise):
347347

348-
- [What the test DOES cover]
349-
- [What remains validated only by code review]
348+
- [What the test DOES cover]
349+
- [What remains validated only by code review]
350350

351351
**Completion checklist**:
352352

@@ -364,7 +364,7 @@ As additional research and implementation details are completed, reconsider thes
364364
- [ ] API matches node:sqlite
365365
```
366366

367-
## File Naming
367+
## File naming
368368

369369
Place TPPs in `doc/todo/${priority}-${desc}.md` during work, move to `doc/done/${date}-${priority}-${desc}.md` when complete:
370370

0 commit comments

Comments
 (0)