feat(skills): port codebase-design vocabulary skill from upstream
Adds engineering/codebase-design/ — shared vocabulary for designing deep
modules (module, interface, seam, adapter, depth, leverage, locality).
Three files: SKILL.md (glossary + principles + R+Py testability examples +
rejected framings); DEEPENING.md (4 dependency categories, seam discipline,
replace-don't-layer); DESIGN-IT-TWICE.md (parallel sub-agent pattern for
exploring 3+ radically different interface designs).
Retargets existing bdd siblings as language-flavored leaves:
- bdd/SKILL.md gains a Vocabulary anchor pointing at codebase-design
- interface-design-{r,py}.md and deep-modules-r.md get "vocab lives
upstream" headers; "deep modules" mention dropped from the py
interface-design description (codebase-design owns it now)
- mocking-{r,py}.md swap "boundary" -> "seam" throughout — upstream
rejects "boundary" as overloaded with DDD's bounded context
- refactoring-r.md cross-links Shallow-modules to DEEPENING.md
Cross-references added in sieve/SKILL.md (Minimal invokes depth),
winnow/SKILL.md (deletion test formalised there), diagnose/SKILL.md
(seam definition for Phase 5's "no correct seam" finding),
domain-modeling/SKILL.md (sibling — vocabulary for solution structure
vs problem domain). README gains a codebase-design bullet.
Source: mattpocock/skills@main engineering/codebase-design/. R+Py
testability examples replace upstream TS originals.
This commit is contained in:
parent
f5227325a3
commit
feb12b1586
@ -50,6 +50,10 @@ skill list.
|
|||||||
- **domain-modeling** — actively build / sharpen a project's domain
|
- **domain-modeling** — actively build / sharpen a project's domain
|
||||||
model — challenge terms, update `CONTEXT.md` inline, offer ADRs only
|
model — challenge terms, update `CONTEXT.md` inline, offer ADRs only
|
||||||
on the three-of-three rule.
|
on the three-of-three rule.
|
||||||
|
- **codebase-design** — shared vocabulary for designing deep modules
|
||||||
|
(module, interface, seam, adapter, depth, leverage, locality);
|
||||||
|
`DEEPENING.md` for dependency-aware seam strategy, `DESIGN-IT-TWICE.md`
|
||||||
|
for parallel-sub-agent interface exploration.
|
||||||
- **r-style** — Tidyverse + `box::use` + `dtplyr` standards with
|
- **r-style** — Tidyverse + `box::use` + `dtplyr` standards with
|
||||||
paired good/bad sibling docs (`box.md`, `tidyverse.md`, `dtplyr.md`).
|
paired good/bad sibling docs (`box.md`, `tidyverse.md`, `dtplyr.md`).
|
||||||
- **dev-python** — orchestrate the full Python workflow (implement →
|
- **dev-python** — orchestrate the full Python workflow (implement →
|
||||||
|
|||||||
@ -12,10 +12,15 @@ description: Drive implementation with a strict red-green-refactor loop where ev
|
|||||||
- Behavior is observable from outside the unit (input → output, state
|
- Behavior is observable from outside the unit (input → output, state
|
||||||
change, side effect) — pure refactors are out of scope.
|
change, side effect) — pure refactors are out of scope.
|
||||||
|
|
||||||
|
## Vocabulary
|
||||||
|
Before step 1, anchor on [../codebase-design/SKILL.md](../codebase-design/SKILL.md) —
|
||||||
|
module, interface, seam, adapter, depth, leverage, locality. Language siblings
|
||||||
|
below restate the vocabulary in R / Python idiom.
|
||||||
|
|
||||||
## Language references — Python
|
## Language references — Python
|
||||||
Pytest only — `@pytest.fixture`, `parametrize`, scenario as docstring.
|
Pytest only — `@pytest.fixture`, `parametrize`, scenario as docstring.
|
||||||
- [tests-py.md](tests-py.md) — paired good/bad examples.
|
- [tests-py.md](tests-py.md) — paired good/bad examples.
|
||||||
- [interface-design-py.md](interface-design-py.md) — DI, pure functions, typing, deep modules. *Before step 1.*
|
- [interface-design-py.md](interface-design-py.md) — DI, pure functions, typing. *Before step 1.*
|
||||||
- [mocking-py.md](mocking-py.md) — boundaries only, façade + DI over patching. *Before `patch` / `monkeypatch`.*
|
- [mocking-py.md](mocking-py.md) — boundaries only, façade + DI over patching. *Before `patch` / `monkeypatch`.*
|
||||||
- [docstrings-py.md](docstrings-py.md) — Google style, types in annotations not prose.
|
- [docstrings-py.md](docstrings-py.md) — Google style, types in annotations not prose.
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,8 @@
|
|||||||
# Deep modules in R
|
# Deep modules in R
|
||||||
|
|
||||||
Adapted from John Ousterhout, *A Philosophy of Software Design*. A **deep
|
Vocabulary and principles in [`../codebase-design/SKILL.md`](../codebase-design/SKILL.md).
|
||||||
module** has a small interface and a large implementation. A **shallow
|
This file shows what deep / shallow look like with `box::use` — the R lever
|
||||||
module** has a large interface and almost no implementation — every helper
|
for controlling the interface.
|
||||||
becomes part of the public contract, which makes the code hard to reason
|
|
||||||
about *and* hard to test.
|
|
||||||
|
|
||||||
In R you control the interface with `box::use` (or NAMESPACE/`@export` in a
|
In R you control the interface with `box::use` (or NAMESPACE/`@export` in a
|
||||||
package). The interface is whatever a caller writes after `box::use(...)`.
|
package). The interface is whatever a caller writes after `box::use(...)`.
|
||||||
|
|||||||
@ -1,8 +1,10 @@
|
|||||||
# Interface design for testability (Python)
|
# Interface design for testability (Python)
|
||||||
|
|
||||||
Rules to apply before writing the test, not after. A deep module (small
|
Vocabulary lives in [`../codebase-design/SKILL.md`](../codebase-design/SKILL.md) —
|
||||||
interface, large implementation — Ousterhout) is the goal; a testable
|
module, interface, seam, adapter, depth. This file is the Python-flavored leaf.
|
||||||
interface is the side effect.
|
|
||||||
|
Rules to apply before writing the test, not after. A deep module is the goal;
|
||||||
|
a testable interface is the side effect.
|
||||||
|
|
||||||
## 1. Dependency injection — pass collaborators, don't construct them
|
## 1. Dependency injection — pass collaborators, don't construct them
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
# Interface design for testability (R)
|
# Interface design for testability (R)
|
||||||
|
|
||||||
|
Vocabulary lives in [`../codebase-design/SKILL.md`](../codebase-design/SKILL.md) —
|
||||||
|
module, interface, seam, adapter. This file is the R-flavored leaf.
|
||||||
|
|
||||||
Three rules. Apply them before writing the test, not after.
|
Three rules. Apply them before writing the test, not after.
|
||||||
|
|
||||||
> Snippets below show only the function bodies; the `box::use(...)`
|
> Snippets below show only the function bodies; the `box::use(...)`
|
||||||
|
|||||||
@ -1,16 +1,16 @@
|
|||||||
# Mocking in Python
|
# Mocking in Python
|
||||||
|
|
||||||
**Mock at system boundaries. Never mock your own internals. Don't patch
|
**Mock at system seams. Never mock your own internals. Don't patch
|
||||||
what you don't own — wrap it.**
|
what you don't own — wrap it.**
|
||||||
|
|
||||||
## Boundaries you may mock
|
## Seams you may mock
|
||||||
|
|
||||||
- HTTP / REST APIs — but through a façade you own (below), or replay
|
- HTTP / REST APIs — but through a façade you own (below), or replay
|
||||||
fixtures with `respx` / `responses`.
|
fixtures with `respx` / `responses`.
|
||||||
- Databases — prefer a real in-memory DB (`sqlite3 :memory:`) or a fake
|
- Databases — prefer a real in-memory DB (`sqlite3 :memory:`) or a fake
|
||||||
repository over patching cursors.
|
repository over patching cursors.
|
||||||
- Time — inject `now: Callable[[], datetime]`, or `monkeypatch` a clock
|
- Time — inject `now: Callable[[], datetime]`, or `monkeypatch` a clock
|
||||||
boundary; never patch `datetime.datetime` globally.
|
seam; never patch `datetime.datetime` globally.
|
||||||
- Randomness — pass an `rng: np.random.Generator` parameter; seed it in
|
- Randomness — pass an `rng: np.random.Generator` parameter; seed it in
|
||||||
the test.
|
the test.
|
||||||
- File system — `tmp_path`. Real temp files are cheaper than mocks.
|
- File system — `tmp_path`. Real temp files are cheaper than mocks.
|
||||||
@ -59,7 +59,7 @@ with patch("httpx.Client.get") as m:
|
|||||||
## Dependency injection over patching
|
## Dependency injection over patching
|
||||||
|
|
||||||
```python
|
```python
|
||||||
# Easy to test — boundary passed in
|
# Easy to test — seam passed in
|
||||||
def annotate(gene_ids: list[str], entrez: EntrezClient) -> list[Annotation]: ...
|
def annotate(gene_ids: list[str], entrez: EntrezClient) -> list[Annotation]: ...
|
||||||
|
|
||||||
# Hard to test — constructs its client internally; forces patching
|
# Hard to test — constructs its client internally; forces patching
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
# Mocking in R
|
# Mocking in R
|
||||||
|
|
||||||
**Mock at system boundaries. Never mock your own code.**
|
**Mock at system seams. Never mock your own code.**
|
||||||
|
|
||||||
> Snippets below show only the function bodies; the `box::use(...)`
|
> Snippets below show only the function bodies; the `box::use(...)`
|
||||||
> prologue is omitted for clarity. Real files start with one — see
|
> prologue is omitted for clarity. Real files start with one — see
|
||||||
> [`../r-style/box.md`](../r-style/box.md).
|
> [`../r-style/box.md`](../r-style/box.md).
|
||||||
|
|
||||||
## Boundaries you may mock
|
## Seams you may mock
|
||||||
|
|
||||||
- HTTP / REST APIs — `httptest2`, `webmockr`, or `httr2::with_mocked_responses()`.
|
- HTTP / REST APIs — `httptest2`, `webmockr`, or `httr2::with_mocked_responses()`.
|
||||||
- Databases — prefer a real test DB (`RSQLite::SQLite()` in-memory) over a
|
- Databases — prefer a real test DB (`RSQLite::SQLite()` in-memory) over a
|
||||||
@ -27,7 +27,7 @@
|
|||||||
If a test feels like it needs to stub an internal helper, that is a signal
|
If a test feels like it needs to stub an internal helper, that is a signal
|
||||||
your function under test is doing two things. Split it.
|
your function under test is doing two things. Split it.
|
||||||
|
|
||||||
## Design for mockability at the boundary
|
## Design for mockability at the seam
|
||||||
|
|
||||||
### Dependency injection over hardcoded constructors
|
### Dependency injection over hardcoded constructors
|
||||||
|
|
||||||
@ -78,10 +78,10 @@ expectations bleeding into another.
|
|||||||
|
|
||||||
- `testthat::local_mocked_bindings(fn = function(...) ...)` — replaces a
|
- `testthat::local_mocked_bindings(fn = function(...) ...)` — replaces a
|
||||||
binding inside the package under test for the scope of one `test_that`.
|
binding inside the package under test for the scope of one `test_that`.
|
||||||
Use only at the *boundary*: stub `httr2::req_perform`, not your own
|
Use only at the *seam*: stub `httr2::req_perform`, not your own
|
||||||
`parse_response`.
|
`parse_response`.
|
||||||
- `mockery::stub(target, "boundary_fn", value)` — same idea, finer-grained.
|
- `mockery::stub(target, "seam_fn", value)` — same idea, finer-grained.
|
||||||
Same rule: only stub at the boundary.
|
Same rule: only stub at the seam.
|
||||||
- `httptest2::with_mock_dir("fixtures/")` — replay recorded HTTP fixtures.
|
- `httptest2::with_mock_dir("fixtures/")` — replay recorded HTTP fixtures.
|
||||||
Best option for integration-style tests against an HTTP service.
|
Best option for integration-style tests against an HTTP service.
|
||||||
|
|
||||||
|
|||||||
@ -44,8 +44,11 @@ parse_response <- function(raw) { ... }
|
|||||||
|
|
||||||
Two modules that always travel together, each exporting one thin function?
|
Two modules that always travel together, each exporting one thin function?
|
||||||
Merge them. A module that exports eight helpers users always call in the
|
Merge them. A module that exports eight helpers users always call in the
|
||||||
same order? Deepen — collapse them behind one entry point. (See
|
same order? Deepen — collapse them behind one entry point. See
|
||||||
`deep-modules-r.md`.)
|
[`deep-modules-r.md`](deep-modules-r.md) for the R shape, and
|
||||||
|
[`../codebase-design/DEEPENING.md`](../codebase-design/DEEPENING.md) for the
|
||||||
|
dependency-aware strategy (replace, don't layer — old tests on the shallow
|
||||||
|
modules become waste once the deepened interface has its own tests).
|
||||||
|
|
||||||
## Feature envy → move logic to where the data lives
|
## Feature envy → move logic to where the data lives
|
||||||
|
|
||||||
|
|||||||
61
skills/engineering/codebase-design/DEEPENING.md
Normal file
61
skills/engineering/codebase-design/DEEPENING.md
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
# Deepening
|
||||||
|
|
||||||
|
How to deepen a cluster of shallow modules safely, given its dependencies.
|
||||||
|
Assumes the vocabulary in [SKILL.md](SKILL.md) — **module**, **interface**,
|
||||||
|
**seam**, **adapter**.
|
||||||
|
|
||||||
|
## Dependency categories
|
||||||
|
|
||||||
|
When assessing a candidate for deepening, classify its dependencies. The
|
||||||
|
category determines how the deepened module is tested across its seam.
|
||||||
|
|
||||||
|
### 1. In-process
|
||||||
|
|
||||||
|
Pure computation, in-memory state, no I/O. Always deepenable — merge the
|
||||||
|
modules and test through the new interface directly. No adapter needed.
|
||||||
|
|
||||||
|
### 2. Local-substitutable
|
||||||
|
|
||||||
|
Dependencies that have local test stand-ins (PGLite for Postgres, in-memory
|
||||||
|
filesystem, `RSQLite::SQLite()` for Postgres). Deepenable if the stand-in
|
||||||
|
exists. The deepened module is tested with the stand-in running in the test
|
||||||
|
suite. The seam is internal; no port at the module's external interface.
|
||||||
|
|
||||||
|
### 3. Remote but owned (Ports & Adapters)
|
||||||
|
|
||||||
|
Your own services across a network boundary (microservices, internal APIs).
|
||||||
|
Define a **port** (interface) at the seam. The deep module owns the logic;
|
||||||
|
the transport is injected as an **adapter**. Tests use an in-memory adapter.
|
||||||
|
Production uses an HTTP/gRPC/queue adapter.
|
||||||
|
|
||||||
|
Recommendation shape: *"Define a port at the seam, implement an HTTP adapter
|
||||||
|
for production and an in-memory adapter for testing, so the logic sits in
|
||||||
|
one deep module even though it's deployed across a network."*
|
||||||
|
|
||||||
|
### 4. True external (Mock)
|
||||||
|
|
||||||
|
Third-party services (Stripe, NCBI, UniProt) you don't control. The deepened
|
||||||
|
module takes the external dependency as an injected port; tests provide a
|
||||||
|
mock adapter.
|
||||||
|
|
||||||
|
## Seam discipline
|
||||||
|
|
||||||
|
- **One adapter means a hypothetical seam. Two adapters means a real one.**
|
||||||
|
Don't introduce a port unless at least two adapters are justified
|
||||||
|
(typically production + test). A single-adapter seam is just indirection.
|
||||||
|
- **Internal seams vs external seams.** A deep module can have internal seams
|
||||||
|
(private to its implementation, used by its own tests) as well as the
|
||||||
|
external seam at its interface. Don't expose internal seams through the
|
||||||
|
interface just because tests use them.
|
||||||
|
|
||||||
|
## Testing strategy: replace, don't layer
|
||||||
|
|
||||||
|
- Old unit tests on shallow modules become waste once tests at the deepened
|
||||||
|
module's interface exist — delete them.
|
||||||
|
- Write new tests at the deepened module's interface. The **interface is the
|
||||||
|
test surface**.
|
||||||
|
- Tests assert on observable outcomes through the interface, not internal
|
||||||
|
state.
|
||||||
|
- Tests should survive internal refactors — they describe behaviour, not
|
||||||
|
implementation. If a test has to change when the implementation changes,
|
||||||
|
it's testing past the interface.
|
||||||
66
skills/engineering/codebase-design/DESIGN-IT-TWICE.md
Normal file
66
skills/engineering/codebase-design/DESIGN-IT-TWICE.md
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
# Design It Twice
|
||||||
|
|
||||||
|
When the user wants to explore alternative interfaces for a chosen deepening
|
||||||
|
candidate, use this parallel sub-agent pattern. Based on "Design It Twice"
|
||||||
|
(Ousterhout) — your first idea is unlikely to be the best.
|
||||||
|
|
||||||
|
Uses the vocabulary in [SKILL.md](SKILL.md) — **module**, **interface**,
|
||||||
|
**seam**, **adapter**, **leverage**.
|
||||||
|
|
||||||
|
## Process
|
||||||
|
|
||||||
|
### 1. Frame the problem space
|
||||||
|
|
||||||
|
Before spawning sub-agents, write a user-facing explanation of the problem
|
||||||
|
space for the chosen candidate:
|
||||||
|
|
||||||
|
- The constraints any new interface would need to satisfy.
|
||||||
|
- The dependencies it would rely on, and which category they fall into
|
||||||
|
(see [DEEPENING.md](DEEPENING.md)).
|
||||||
|
- A rough illustrative code sketch to ground the constraints — not a
|
||||||
|
proposal, just a way to make the constraints concrete.
|
||||||
|
|
||||||
|
Show this to the user, then immediately proceed to Step 2. The user reads and
|
||||||
|
thinks while the sub-agents work in parallel.
|
||||||
|
|
||||||
|
### 2. Spawn sub-agents
|
||||||
|
|
||||||
|
Spawn 3+ sub-agents in parallel using the Agent tool — **one message with
|
||||||
|
multiple Agent tool uses** so they run concurrently. Each must produce a
|
||||||
|
**radically different** interface for the deepened module. Use
|
||||||
|
`subagent_type: claude` (general-purpose) so each has full read + search.
|
||||||
|
|
||||||
|
Prompt each sub-agent with a separate technical brief (file paths, coupling
|
||||||
|
details, dependency category from [DEEPENING.md](DEEPENING.md), what sits
|
||||||
|
behind the seam). The brief is independent of the user-facing problem-space
|
||||||
|
explanation in Step 1. Give each agent a different design constraint:
|
||||||
|
|
||||||
|
- Agent 1: "Minimize the interface — aim for 1–3 entry points max. Maximise
|
||||||
|
leverage per entry point."
|
||||||
|
- Agent 2: "Maximise flexibility — support many use cases and extension."
|
||||||
|
- Agent 3: "Optimise for the most common caller — make the default case
|
||||||
|
trivial."
|
||||||
|
- Agent 4 (if applicable): "Design around ports & adapters for cross-seam
|
||||||
|
dependencies."
|
||||||
|
|
||||||
|
Include both [SKILL.md](SKILL.md) vocabulary and `CONTEXT.md` vocabulary in
|
||||||
|
the brief so each sub-agent names things consistently with the architecture
|
||||||
|
language and the project's domain language.
|
||||||
|
|
||||||
|
Each sub-agent outputs:
|
||||||
|
|
||||||
|
1. Interface (types, methods, params — plus invariants, ordering, error modes).
|
||||||
|
2. Usage example showing how callers use it.
|
||||||
|
3. What the implementation hides behind the seam.
|
||||||
|
4. Dependency strategy and adapters (see [DEEPENING.md](DEEPENING.md)).
|
||||||
|
5. Trade-offs — where leverage is high, where it's thin.
|
||||||
|
|
||||||
|
### 3. Present and compare
|
||||||
|
|
||||||
|
Present designs sequentially so the user can absorb each one, then compare
|
||||||
|
them in prose. Contrast by **depth** (leverage at the interface),
|
||||||
|
**locality** (where change concentrates), and **seam placement**.
|
||||||
|
|
||||||
|
After comparing, give your own recommendation: which design you think is
|
||||||
|
strongest and why. If elements from different designs would combine well,
|
||||||
|
propose a hybrid. Be opinionated — the user wants a strong read, not a menu.
|
||||||
100
skills/engineering/codebase-design/SKILL.md
Normal file
100
skills/engineering/codebase-design/SKILL.md
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
---
|
||||||
|
name: codebase-design
|
||||||
|
description: Shared vocabulary for designing deep modules. Use when the user wants to design or improve a module's interface, find deepening opportunities, decide where a seam goes, make code more testable or AI-navigable, or when another skill needs the deep-module vocabulary.
|
||||||
|
---
|
||||||
|
|
||||||
|
# codebase-design
|
||||||
|
|
||||||
|
Design **deep modules**: a lot of behaviour behind a small interface, placed
|
||||||
|
at a clean seam, testable through that interface. The aim is leverage for
|
||||||
|
callers, locality for maintainers, and testability for everyone.
|
||||||
|
|
||||||
|
## Glossary
|
||||||
|
|
||||||
|
Use these exactly; don't substitute "component", "service", "API", "boundary".
|
||||||
|
|
||||||
|
**Module** — anything with an interface and an implementation. Scale-agnostic:
|
||||||
|
function, class, package, tier-spanning slice. _Avoid_: unit, component, service.
|
||||||
|
|
||||||
|
**Interface** — everything a caller must know to use the module correctly:
|
||||||
|
type signature, invariants, ordering, error modes, configuration, performance.
|
||||||
|
_Avoid_: API, signature (type-level only).
|
||||||
|
|
||||||
|
**Implementation** — what's inside a module. Distinct from **Adapter**: a small
|
||||||
|
adapter can wrap a large implementation (a Postgres repo), or vice versa.
|
||||||
|
|
||||||
|
**Depth** — leverage at the interface: behaviour a caller exercises per unit
|
||||||
|
of interface learned. **Deep** = much behaviour behind a small interface;
|
||||||
|
**shallow** = interface nearly as complex as impl.
|
||||||
|
|
||||||
|
**Seam** _(Michael Feathers)_ — a place where you can alter behaviour without
|
||||||
|
editing in that place; the *location* at which a module's interface lives.
|
||||||
|
_Avoid_: boundary (overloaded with DDD's bounded context).
|
||||||
|
|
||||||
|
**Adapter** — a concrete thing that satisfies an interface at a seam. *Role*,
|
||||||
|
not substance.
|
||||||
|
|
||||||
|
**Leverage** — what callers get from depth: more capability per unit of
|
||||||
|
interface learned. One impl pays back across N call sites, M tests.
|
||||||
|
|
||||||
|
**Locality** — what maintainers get from depth: change, bugs, knowledge,
|
||||||
|
verification concentrate in one place. Fix once, fixed everywhere.
|
||||||
|
|
||||||
|
## Deep vs shallow
|
||||||
|
|
||||||
|
A **deep** module = small interface (few methods, simple params) over large
|
||||||
|
implementation (complex logic hidden). **Shallow** = the inverse, mostly
|
||||||
|
pass-through. Avoid shallow: reduce methods, simplify params, hide more inside.
|
||||||
|
|
||||||
|
## Principles
|
||||||
|
|
||||||
|
- **Depth is a property of the interface, not the implementation.** A deep
|
||||||
|
module can be composed of small mockable parts internally; **internal
|
||||||
|
seams** (private, used by its own tests) coexist with the **external seam**.
|
||||||
|
- **The deletion test.** Imagine deleting the module. If complexity vanishes,
|
||||||
|
it was a pass-through. If complexity reappears across N callers, it was
|
||||||
|
earning its keep.
|
||||||
|
- **The interface is the test surface.** Callers and tests cross the same
|
||||||
|
seam. To test *past* the interface is to find the module is the wrong shape.
|
||||||
|
- **One adapter = hypothetical seam; two = real one.** Don't introduce a seam
|
||||||
|
unless something actually varies across it.
|
||||||
|
|
||||||
|
## Designing for testability
|
||||||
|
|
||||||
|
**Accept dependencies, don't create them.**
|
||||||
|
|
||||||
|
```r
|
||||||
|
# R: pass the client; default keeps callers ergonomic
|
||||||
|
fetch_orders <- function(order_id, client = modb_client()) client$get(order_id)
|
||||||
|
```
|
||||||
|
|
||||||
|
```python
|
||||||
|
# Python: optional parameter, same shape
|
||||||
|
def fetch_orders(order_id: str, client: ModbClient | None = None) -> Order:
|
||||||
|
return (client or ModbClient()).get(order_id)
|
||||||
|
```
|
||||||
|
|
||||||
|
Constructing the client inside buries the dependency past the interface.
|
||||||
|
|
||||||
|
**Return results, don't produce side effects.**
|
||||||
|
|
||||||
|
```r
|
||||||
|
# R: return the new value
|
||||||
|
calculate_discount <- function(cart) cart$total - discount(cart)
|
||||||
|
```
|
||||||
|
|
||||||
|
```python
|
||||||
|
# Python: return the new value
|
||||||
|
def calculate_discount(cart: Cart) -> Decimal:
|
||||||
|
return cart.total - discount(cart)
|
||||||
|
```
|
||||||
|
|
||||||
|
Mutating in place hides the effect and couples every test to caller state.
|
||||||
|
|
||||||
|
## Rejected framings
|
||||||
|
|
||||||
|
- **Depth as impl-lines ÷ interface-lines** (Ousterhout): rewards padding. Use depth-as-leverage instead.
|
||||||
|
- **"Interface" = the TypeScript `interface` keyword or a class's public methods**: too narrow — interface here is every fact a caller must know.
|
||||||
|
- **"Boundary"**: overloaded with DDD's bounded context. Say **seam** or **interface**.
|
||||||
|
|
||||||
|
[DEEPENING.md](DEEPENING.md) — dependency categories, seam discipline, replace-don't-layer testing. [DESIGN-IT-TWICE.md](DESIGN-IT-TWICE.md) — parallel sub-agents to design the interface several radically different ways; compare on depth, locality, seam placement.
|
||||||
@ -95,5 +95,6 @@ Then ask: **what would have prevented this bug?**
|
|||||||
- [../bdd/SKILL.md](../bdd/SKILL.md) — phase 5 is a bdd cycle.
|
- [../bdd/SKILL.md](../bdd/SKILL.md) — phase 5 is a bdd cycle.
|
||||||
- [../bdd/refactoring-r.md](../bdd/refactoring-r.md) — file
|
- [../bdd/refactoring-r.md](../bdd/refactoring-r.md) — file
|
||||||
architectural follow-ups here.
|
architectural follow-ups here.
|
||||||
|
- [../codebase-design/SKILL.md](../codebase-design/SKILL.md) — definition of **seam** (Phase 5's "no correct seam" finding).
|
||||||
- [../domain-modeling/SKILL.md](../domain-modeling/SKILL.md) — phase 3
|
- [../domain-modeling/SKILL.md](../domain-modeling/SKILL.md) — phase 3
|
||||||
hypothesis names should use canonical terms from `CONTEXT.md`.
|
hypothesis names should use canonical terms from `CONTEXT.md`.
|
||||||
|
|||||||
@ -82,6 +82,10 @@ per-context `CONTEXT.md` under each sub-root.
|
|||||||
confirming the first such write.
|
confirming the first such write.
|
||||||
|
|
||||||
## See also
|
## See also
|
||||||
|
- [../codebase-design/SKILL.md](../codebase-design/SKILL.md) — sibling
|
||||||
|
vocabulary skill. **domain-modeling** pins terms for the *problem domain*
|
||||||
|
(CONTEXT.md, glossary); **codebase-design** pins terms for the *solution
|
||||||
|
structure* (module, interface, seam, adapter).
|
||||||
- [../grill-with-docs/SKILL.md](../grill-with-docs/SKILL.md) — the
|
- [../grill-with-docs/SKILL.md](../grill-with-docs/SKILL.md) — the
|
||||||
user-invoked router that pairs this skill with a Socratic interview.
|
user-invoked router that pairs this skill with a Socratic interview.
|
||||||
- [../bdd/SKILL.md](../bdd/SKILL.md) — once vocabulary is pinned, the
|
- [../bdd/SKILL.md](../bdd/SKILL.md) — once vocabulary is pinned, the
|
||||||
|
|||||||
@ -79,6 +79,9 @@ describe`), not per keystroke — otherwise it fights iteration.
|
|||||||
## See also
|
## See also
|
||||||
- [`../winnow/SKILL.md`](../winnow/SKILL.md) — the mechanical after-the-fact
|
- [`../winnow/SKILL.md`](../winnow/SKILL.md) — the mechanical after-the-fact
|
||||||
audit. The sieve judges entry; winnow clears the field.
|
audit. The sieve judges entry; winnow clears the field.
|
||||||
|
- [`../codebase-design/SKILL.md`](../codebase-design/SKILL.md) — *Minimal*
|
||||||
|
invokes **depth** intuition. The leanest form that works tends to be the
|
||||||
|
deepest: small interface, large implementation hidden behind it.
|
||||||
- [`../../productivity/jj-atomic/SKILL.md`](../../productivity/jj-atomic/SKILL.md)
|
- [`../../productivity/jj-atomic/SKILL.md`](../../productivity/jj-atomic/SKILL.md)
|
||||||
— the seal where the sieve fires.
|
— the seal where the sieve fires.
|
||||||
- [`../grill-with-docs/SKILL.md`](../grill-with-docs/SKILL.md)
|
- [`../grill-with-docs/SKILL.md`](../grill-with-docs/SKILL.md)
|
||||||
|
|||||||
@ -76,6 +76,10 @@ it sharp.
|
|||||||
## See also
|
## See also
|
||||||
- [`../sieve/SKILL.md`](../sieve/SKILL.md) — the judgment gate. Sieve decides
|
- [`../sieve/SKILL.md`](../sieve/SKILL.md) — the judgment gate. Sieve decides
|
||||||
what earns its place; winnow mechanically clears what doesn't.
|
what earns its place; winnow mechanically clears what doesn't.
|
||||||
|
- [`../codebase-design/SKILL.md`](../codebase-design/SKILL.md) — the
|
||||||
|
**deletion test** formalised: if removing a module makes complexity
|
||||||
|
vanish, it was a pass-through; if it reappears across N callers, it earned
|
||||||
|
its keep. The `delete` and `yagni` tags are this test mechanised.
|
||||||
- [`../bdd/refactoring-r.md`](../bdd/refactoring-r.md) — file the
|
- [`../bdd/refactoring-r.md`](../bdd/refactoring-r.md) — file the
|
||||||
architectural follow-ups a winnow surfaces; don't auto-cut them mid-pass.
|
architectural follow-ups a winnow surfaces; don't auto-cut them mid-pass.
|
||||||
- [`../review-angles/SKILL.md`](../review-angles/SKILL.md) — the correctness
|
- [`../review-angles/SKILL.md`](../review-angles/SKILL.md) — the correctness
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user