@hobin/developer 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +215 -372
- package/REFERENCE_ROUTING.md +243 -0
- package/extensions/developer.ts +533 -18
- package/extensions/machine.ts +45 -0
- package/extensions/references/behavior-preserving-structural-change.md +87 -8
- package/extensions/skills.ts +330 -52
- package/extensions/state.ts +227 -2
- package/package.json +9 -3
- package/skills/abstraction-review/SKILL.md +37 -23
- package/skills/abstraction-review/reference-policy.json +66 -0
- package/skills/abstraction-review/references/field-card.md +113 -168
- package/skills/abstraction-review/references/repair-table.md +66 -80
- package/skills/abstraction-review/references/worked-examples.md +79 -256
- package/skills/model/SKILL.md +31 -13
- package/skills/model/reference-policy.json +96 -0
- package/skills/model/references/contract-and-replacement-models.md +112 -0
- package/skills/model/references/logic-query-semantics.md +89 -0
- package/skills/model/references/planning-models.md +75 -0
- package/skills/model/references/problem-modeling.md +143 -276
- package/skills/model/references/proof-obligations.md +71 -0
- package/skills/model/references/relational-constraint-models.md +110 -0
- package/skills/model/references/solver-result-boundaries.md +83 -0
- package/skills/model/references/temporal-behavior-models.md +106 -0
- package/skills/naming-judgment/SKILL.md +17 -4
- package/skills/naming-judgment/reference-policy.json +29 -0
- package/skills/naming-judgment/references/domain-naming.md +29 -10
- package/skills/schedule/SKILL.md +16 -6
- package/skills/schedule/reference-policy.json +29 -0
- package/skills/schedule/references/structural-change-timing.md +81 -18
- package/skills/signal/SKILL.md +17 -6
- package/skills/signal/reference-policy.json +29 -0
- package/skills/signal/references/structural-movement.md +87 -14
- package/skills/sketch/SKILL.md +38 -42
- package/skills/sketch/reference-policy.json +212 -0
- package/skills/sketch/references/accumulator-invariants.md +125 -0
- package/skills/sketch/references/closure-and-conventional-interfaces.md +87 -0
- package/skills/sketch/references/composition-by-wishes.md +69 -0
- package/skills/sketch/references/data-driven-design.md +99 -22
- package/skills/sketch/references/data-shape-template-catalog.md +58 -19
- package/skills/sketch/references/design-levels-and-boundaries.md +133 -0
- package/skills/sketch/references/earned-abstraction.md +75 -0
- package/skills/sketch/references/generative-recursion.md +122 -0
- package/skills/sketch/references/generic-dispatch-systems.md +75 -0
- package/skills/sketch/references/language-semantics.md +82 -0
- package/skills/sketch/references/meaning-preserving-conversions.md +69 -0
- package/skills/sketch/references/process-shape-and-resources.md +157 -0
- package/skills/sketch/references/representation-barriers.md +73 -0
- package/skills/sketch/references/responsibility-and-collaboration.md +108 -0
- package/skills/sketch/references/runtime-and-compilation.md +84 -0
- package/skills/sketch/references/selection-and-creation.md +76 -0
- package/skills/sketch/references/state-history-and-order.md +126 -0
- package/skills/sketch/references/type-transitions.md +54 -0
- package/skills/sketch/references/variation-roles.md +59 -0
- package/skills/verify/SKILL.md +17 -6
- package/skills/verify/reference-policy.json +30 -0
- package/skills/verify/references/verifier-selection-and-pass-but-wrong.md +152 -192
- package/SOURCES.md +0 -104
- package/skills/abstraction-review/references/recipe-cards.md +0 -322
- package/skills/model/references/worked-models-and-specialized-techniques.md +0 -218
- package/skills/sketch/references/abstraction-barriers-and-closure.md +0 -160
- package/skills/sketch/references/abstraction-composition-and-state.md +0 -184
- package/skills/sketch/references/composition-generative-recursion-and-accumulators.md +0 -196
- package/skills/sketch/references/generic-operations-and-languages.md +0 -134
- package/skills/sketch/references/processes-state-and-time.md +0 -171
- package/skills/sketch/references/responsibility-and-variation.md +0 -245
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
# Abstraction Review Recipe Cards
|
|
2
|
-
|
|
3
|
-
Use this deck when the review needs a construction rule, not only a layer name.
|
|
4
|
-
Each card must produce an artifact and a stop check.
|
|
5
|
-
|
|
6
|
-
Read [the worked examples](worked-examples.md) when a card's compact rule is not
|
|
7
|
-
enough to calibrate a real candidate. When a stop check fails, use
|
|
8
|
-
[the repair table](repair-table.md) instead of polishing the same surface.
|
|
9
|
-
|
|
10
|
-
## Contents
|
|
11
|
-
|
|
12
|
-
- Pocket Deck
|
|
13
|
-
- Procedure -> Process Reality Check
|
|
14
|
-
- Movement Pattern Extraction
|
|
15
|
-
- Responsibility Boundary
|
|
16
|
-
- Invariant Iteration
|
|
17
|
-
- Data Abstraction Boundary
|
|
18
|
-
- Closure Composition Unit
|
|
19
|
-
- Dispatch Registration
|
|
20
|
-
- Meaning-Preserving Path
|
|
21
|
-
- Notation As Data
|
|
22
|
-
- History Placement
|
|
23
|
-
- Event Order Protection
|
|
24
|
-
|
|
25
|
-
## Pocket Deck
|
|
26
|
-
|
|
27
|
-
| Card | Trigger | Fill first | Derive | Stop | Repair if fails |
|
|
28
|
-
| --- | --- | --- | --- | --- | --- |
|
|
29
|
-
| Procedure -> Process Reality Check | Result is plausible but process shape is unclear | procedure text, sample input, expected result | trace deferred work, state updates, duplicated work, cost | result, shape, and cost are all explainable | move to Law or Time |
|
|
30
|
-
| Movement Pattern Extraction | Similar cases move together but differ in stable roles | concrete cases side by side, common movement, varying roles | keep common movement as body; lift stable variation roles to parameters, callbacks, or strategies | old cases become simple calls and new case is expressible | split, inline, or return to Language |
|
|
31
|
-
| Responsibility Boundary | Knowledge and behavior appear owned by the wrong unit | current owners, messages, data, callers, change reasons | group knowledge with behavior and state the smallest role contract | representative change becomes local without context leaks | split, inline, or return to Model |
|
|
32
|
-
| Invariant Iteration | Recursion or state should become a stable transition | original meaning, state variables, transition candidate | write `processed meaning + remaining meaning = original meaning` using the domain operation | initial, step, and final checks pass | return to Run trace or reduce state variables |
|
|
33
|
-
| Data Abstraction Boundary | Caller knows raw representation | domain value, operations, representation candidates | create constructor, selector, predicate, and operation vocabulary | caller code stops touching raw representation | move to Unit or Engine |
|
|
34
|
-
| Closure Composition Unit | Operation results cannot feed later operations | candidate unit, operation list, preserved meaning | mark closed operations vs observers/finalizers | closed operations build larger values of the same unit | move final effect outside the unit |
|
|
35
|
-
| Dispatch Registration | New type/provider/case changes old branches | variant axis, operation axis, current branches | turn each branch into `(variant, operation) -> method` | fake variant is added by registration only | choose axes again or use Meaning-Preserving Path |
|
|
36
|
-
| Meaning-Preserving Path | Mixed worlds need operation without hidden loss | source worlds, operation, candidate paths | draw direct/coerce/canonicalize/reject graph | legal path, loss, and unsupported cases are explicit | narrow preserved meaning or reject |
|
|
37
|
-
| Notation As Data | String/index manipulation stands in for semantic rules | expression cases, parts, transformations | make predicate/selector/constructor vocabulary | rewrite rule ignores raw layout | move to Boundary or Engine |
|
|
38
|
-
| History Placement | Same call depends on history | behavior, required history, interaction model | choose pure, local state, or stream/log placement | hidden summary or explicit history matches contract | move to Event Order or Boundary |
|
|
39
|
-
| Event Order Protection | Interleaving changes correctness | events, shared meaning, possible interleavings | state order law and protected region or merge policy | forbidden interleaving is blocked for a stated reason | narrow order law or return to History |
|
|
40
|
-
|
|
41
|
-
## Card Details
|
|
42
|
-
|
|
43
|
-
### Procedure -> Process Reality Check
|
|
44
|
-
|
|
45
|
-
Use when code is textually simple but execution may grow the wrong process.
|
|
46
|
-
|
|
47
|
-
Output artifact:
|
|
48
|
-
|
|
49
|
-
```text
|
|
50
|
-
process trace:
|
|
51
|
-
input -> stage -> stage -> result
|
|
52
|
-
shape:
|
|
53
|
-
recursive / iterative / tree / delayed / stateful
|
|
54
|
-
cost note:
|
|
55
|
-
time, space, duplicated work, hidden order
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
Promote only if the abstraction promise includes the real process shape, not
|
|
59
|
-
just the returned value.
|
|
60
|
-
|
|
61
|
-
### Movement Pattern Extraction
|
|
62
|
-
|
|
63
|
-
Use when abstraction pressure comes from repeated movement, not from a single
|
|
64
|
-
interface wish.
|
|
65
|
-
|
|
66
|
-
Input artifact:
|
|
67
|
-
|
|
68
|
-
```text
|
|
69
|
-
cases:
|
|
70
|
-
two or more concrete functions, workflows, tests, or traces
|
|
71
|
-
common movement:
|
|
72
|
-
steps that move together across cases
|
|
73
|
-
variation roles:
|
|
74
|
-
stable differences such as predicate, term, next, combine, strategy, policy
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
Derivation:
|
|
78
|
-
|
|
79
|
-
```text
|
|
80
|
-
body:
|
|
81
|
-
keep the common movement
|
|
82
|
-
parameters:
|
|
83
|
-
lift stable variation roles
|
|
84
|
-
name:
|
|
85
|
-
describe the concept, not the implementation trick
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
Output artifact:
|
|
89
|
-
|
|
90
|
-
```text
|
|
91
|
-
abstraction candidate:
|
|
92
|
-
name, signature, body skeleton
|
|
93
|
-
role table:
|
|
94
|
-
case -> variation role values
|
|
95
|
-
process note:
|
|
96
|
-
whether the generated process/cost changes
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
Stop check: each old case is a simple call, and at least one realistic new case
|
|
100
|
-
can be expressed without adding a new option that exposes internals.
|
|
101
|
-
|
|
102
|
-
Reject if the cases only look textually similar but carry different
|
|
103
|
-
responsibilities. Split if variation roles are not stable.
|
|
104
|
-
|
|
105
|
-
### Responsibility Boundary
|
|
106
|
-
|
|
107
|
-
Use when repeated arguments, data clumps, feature envy, conditional behavior, or
|
|
108
|
-
several change reasons suggest that knowledge and behavior have the wrong owner.
|
|
109
|
-
|
|
110
|
-
Input artifact:
|
|
111
|
-
|
|
112
|
-
```text
|
|
113
|
-
current owners:
|
|
114
|
-
unit -> knowledge, behavior, coordination, creation
|
|
115
|
-
messages:
|
|
116
|
-
callers -> requests -> receivers
|
|
117
|
-
pressure:
|
|
118
|
-
representative accepted change and affected path
|
|
119
|
-
candidate:
|
|
120
|
-
knowledge and behavior proposed to move together
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
Derivation:
|
|
124
|
-
|
|
125
|
-
1. group behavior with the knowledge needed to answer its messages;
|
|
126
|
-
2. separate domain responsibility from coordination and object creation;
|
|
127
|
-
3. state the smallest caller-visible role contract;
|
|
128
|
-
4. identify old context callers should stop knowing;
|
|
129
|
-
5. test a representative change against old and candidate ownership.
|
|
130
|
-
|
|
131
|
-
Output artifact:
|
|
132
|
-
|
|
133
|
-
```text
|
|
134
|
-
responsibility: name and reason to change
|
|
135
|
-
knowledge: data or history it owns
|
|
136
|
-
messages: minimal protocol
|
|
137
|
-
hidden context: mechanics removed from callers
|
|
138
|
-
creation boundary: who selects or constructs it
|
|
139
|
-
rejected alternatives: inline, split, or different owner
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
Stop check: the representative change is local to a coherent owner, callers use
|
|
143
|
-
messages rather than extracting its knowledge, and the candidate does not need
|
|
144
|
-
unrelated context from the old host. Reject or split when the candidate is only
|
|
145
|
-
a bag of moved methods, a generic service, or a pattern-shaped destination.
|
|
146
|
-
|
|
147
|
-
### Invariant Iteration
|
|
148
|
-
|
|
149
|
-
Use when state variables or accumulators need meaning.
|
|
150
|
-
|
|
151
|
-
Output artifact:
|
|
152
|
-
|
|
153
|
-
```text
|
|
154
|
-
invariant:
|
|
155
|
-
what state variables preserve
|
|
156
|
-
initial:
|
|
157
|
-
why the invariant starts true
|
|
158
|
-
transition:
|
|
159
|
-
why one step keeps it true
|
|
160
|
-
final:
|
|
161
|
-
why termination exposes the answer
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
If the invariant is hard to state, decide `revise-model`. If it is true but
|
|
165
|
-
expensive, review representation or operation placement.
|
|
166
|
-
|
|
167
|
-
### Data Abstraction Boundary
|
|
168
|
-
|
|
169
|
-
Use when callers know too much.
|
|
170
|
-
|
|
171
|
-
Output artifact:
|
|
172
|
-
|
|
173
|
-
```text
|
|
174
|
-
public handles:
|
|
175
|
-
constructors / selectors / predicates / generic operations
|
|
176
|
-
representation law:
|
|
177
|
-
what callers may trust
|
|
178
|
-
hidden freedom:
|
|
179
|
-
internal details that may change
|
|
180
|
-
creation policy:
|
|
181
|
-
validation / normalization / simplification location
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
If no detail is hidden, reject or inline. If policy is hidden in consumers,
|
|
185
|
-
decide `revise-surface`.
|
|
186
|
-
|
|
187
|
-
### Closure Composition Unit
|
|
188
|
-
|
|
189
|
-
Use when the goal is an algebra of reusable pieces.
|
|
190
|
-
|
|
191
|
-
Output artifact:
|
|
192
|
-
|
|
193
|
-
```text
|
|
194
|
-
unit predicate:
|
|
195
|
-
what belongs to the world
|
|
196
|
-
closed operations:
|
|
197
|
-
unit -> unit, unit x unit -> unit
|
|
198
|
-
observers/finalizers:
|
|
199
|
-
unit -> outside
|
|
200
|
-
illegal move:
|
|
201
|
-
operation that leaks or breaks the unit
|
|
202
|
-
```
|
|
203
|
-
|
|
204
|
-
Do not make everything chainable. Preserve the central unit and move final
|
|
205
|
-
effects to an explicit boundary.
|
|
206
|
-
|
|
207
|
-
### Dispatch Registration
|
|
208
|
-
|
|
209
|
-
Use when variation should be additive.
|
|
210
|
-
|
|
211
|
-
Output artifact:
|
|
212
|
-
|
|
213
|
-
```text
|
|
214
|
-
table:
|
|
215
|
-
variants x operations
|
|
216
|
-
registration:
|
|
217
|
-
register(variant, operation, method)
|
|
218
|
-
lookup:
|
|
219
|
-
applyGeneric(operation, value...)
|
|
220
|
-
unsupported:
|
|
221
|
-
explicit missing capability policy
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
Stop check: add a fake variant. Existing callers and existing variant packages
|
|
225
|
-
should not know its representation.
|
|
226
|
-
|
|
227
|
-
### Meaning-Preserving Path
|
|
228
|
-
|
|
229
|
-
Use when values cross worlds.
|
|
230
|
-
|
|
231
|
-
Output artifact:
|
|
232
|
-
|
|
233
|
-
```text
|
|
234
|
-
conversion graph:
|
|
235
|
-
source -> target paths
|
|
236
|
-
preserved meaning:
|
|
237
|
-
what must survive conversion
|
|
238
|
-
policy:
|
|
239
|
-
direct / raise / canonicalize / reject
|
|
240
|
-
loss note:
|
|
241
|
-
precision, identity, ordering, capability
|
|
242
|
-
```
|
|
243
|
-
|
|
244
|
-
Unsupported is a legitimate boundary, not a failure, when meaning cannot be
|
|
245
|
-
preserved.
|
|
246
|
-
|
|
247
|
-
### Notation As Data
|
|
248
|
-
|
|
249
|
-
Use when a language, expression, query, or formula must be inspected or
|
|
250
|
-
rewritten.
|
|
251
|
-
|
|
252
|
-
Output artifact:
|
|
253
|
-
|
|
254
|
-
```text
|
|
255
|
-
expression boundary:
|
|
256
|
-
predicates / selectors / constructors
|
|
257
|
-
transform rules:
|
|
258
|
-
algorithms written against the boundary
|
|
259
|
-
render/evaluate boundary:
|
|
260
|
-
where data becomes displayed or executable again
|
|
261
|
-
```
|
|
262
|
-
|
|
263
|
-
If transformation rules depend on indexes or string layout, the boundary is not
|
|
264
|
-
real yet.
|
|
265
|
-
|
|
266
|
-
### History Placement
|
|
267
|
-
|
|
268
|
-
Use when current behavior cannot be understood from current input alone.
|
|
269
|
-
|
|
270
|
-
Output artifact:
|
|
271
|
-
|
|
272
|
-
```text
|
|
273
|
-
placement:
|
|
274
|
-
pure / local state / stream-log
|
|
275
|
-
state contract:
|
|
276
|
-
what hidden state summarizes
|
|
277
|
-
stream contract:
|
|
278
|
-
what each time-indexed value means
|
|
279
|
-
order risk:
|
|
280
|
-
where histories merge or conflict
|
|
281
|
-
```
|
|
282
|
-
|
|
283
|
-
Local state hides history for API simplicity. Stream/log exposes history for
|
|
284
|
-
composition, replay, audit, and merge reasoning.
|
|
285
|
-
|
|
286
|
-
### Event Order Protection
|
|
287
|
-
|
|
288
|
-
Use when order is part of meaning.
|
|
289
|
-
|
|
290
|
-
Output artifact:
|
|
291
|
-
|
|
292
|
-
```text
|
|
293
|
-
order law:
|
|
294
|
-
required happens-before relation
|
|
295
|
-
protected region:
|
|
296
|
-
steps that must appear atomic
|
|
297
|
-
mechanism:
|
|
298
|
-
lock / transaction / queue / serializer / merge policy
|
|
299
|
-
cost:
|
|
300
|
-
waiting, reduced parallelism, fairness tradeoff
|
|
301
|
-
```
|
|
302
|
-
|
|
303
|
-
If everything must be serialized, the order law is probably too broad.
|
|
304
|
-
|
|
305
|
-
## Source Trace
|
|
306
|
-
|
|
307
|
-
- Harold Abelson and Gerald Jay Sussman with Julie Sussman, *Structure and
|
|
308
|
-
Interpretation of Computer Programs*, Second Edition, MIT Press, 1996:
|
|
309
|
-
procedure/process distinction, data abstraction, closure, generic dispatch,
|
|
310
|
-
state/history, and metalinguistic boundaries.
|
|
311
|
-
- Matthias Felleisen, Robert Bruce Findler, Matthew Flatt, and Shriram
|
|
312
|
-
Krishnamurthi, *How to Design Programs, Second Edition*, MIT Press, 2018:
|
|
313
|
-
templates, abstraction from concrete examples, generative recursion, and
|
|
314
|
-
accumulator invariants.
|
|
315
|
-
- Sandi Metz, Katrina Owen, and TJ Stankus, *99 Bottles of OOP*, Second
|
|
316
|
-
Edition, version 2.2.2, 2024: movement patterns, responsibility extraction,
|
|
317
|
-
messages, substitution, polymorphic roles, type transitions, and factory
|
|
318
|
-
tradeoffs.
|
|
319
|
-
- Hillel Wayne, *Logic for Programmers*, version 0.14.0, May 4, 2026:
|
|
320
|
-
contracts, safe replacement, invariants, and meaning-preserving model changes.
|
|
321
|
-
- Zachary Tellman, *Elements of Clojure*, 2019: indirection cost, module
|
|
322
|
-
assumptions, principled components, adaptable interfaces, and composition.
|
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
# Worked Models And Specialized Techniques
|
|
2
|
-
|
|
3
|
-
Use this reference to calibrate the artifacts in
|
|
4
|
-
[Problem Modeling](problem-modeling.md). Each technique starts from a different
|
|
5
|
-
uncertainty. Select the smallest model that can expose the consequential mistake.
|
|
6
|
-
|
|
7
|
-
## Boolean Policy: Access Rule
|
|
8
|
-
|
|
9
|
-
Prose: “Editors can publish their own drafts, and admins can publish anything,
|
|
10
|
-
unless the document is archived.”
|
|
11
|
-
|
|
12
|
-
```text
|
|
13
|
-
domain: user in Users, document in Documents
|
|
14
|
-
facts:
|
|
15
|
-
role(user) in {viewer, editor, admin}
|
|
16
|
-
owner(document) in Users
|
|
17
|
-
status(document) in {draft, published, archived}
|
|
18
|
-
|
|
19
|
-
canPublish(user, document) =
|
|
20
|
-
status(document) != archived
|
|
21
|
-
&& (role(user) == admin
|
|
22
|
-
|| (role(user) == editor && owner(document) == user))
|
|
23
|
-
|
|
24
|
-
forbidden counterexample:
|
|
25
|
-
canPublish(user, document) && status(document) == archived
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
| archived | admin | editor owns | result |
|
|
29
|
-
| --- | --- | --- | --- |
|
|
30
|
-
| yes | any | any | false |
|
|
31
|
-
| no | yes | any | true |
|
|
32
|
-
| no | no | yes | true |
|
|
33
|
-
| no | no | no | false |
|
|
34
|
-
|
|
35
|
-
Unknown: whether an editor may republish a published document. Keep it human-
|
|
36
|
-
owned because the prose names drafts only. Verify the four partitions and one
|
|
37
|
-
real authorization integration; do not leave the guarantee in a UI guard alone.
|
|
38
|
-
|
|
39
|
-
## Relational Data And Constraints
|
|
40
|
-
|
|
41
|
-
Requirement: each department has at most one active manager at a time, and every
|
|
42
|
-
manager row refers to existing entities.
|
|
43
|
-
|
|
44
|
-
```text
|
|
45
|
-
Employee(id)
|
|
46
|
-
Department(id)
|
|
47
|
-
Management(employeeId, departmentId, start, end?)
|
|
48
|
-
|
|
49
|
-
all m in Management:
|
|
50
|
-
some e in Employee: e.id == m.employeeId
|
|
51
|
-
some d in Department: d.id == m.departmentId
|
|
52
|
-
m.end is absent || m.start < m.end
|
|
53
|
-
|
|
54
|
-
all a, b in Management where a != b
|
|
55
|
-
&& a.departmentId == b.departmentId:
|
|
56
|
-
intervalsDoNotOverlap(a, b)
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
The last property may require an exclusion constraint, serialized transaction,
|
|
60
|
-
or application check plus locking depending on the database. A nullable `end`
|
|
61
|
-
needs an explicit open-interval meaning. Exercise historical, current, future,
|
|
62
|
-
overlapping-boundary, and missing-foreign-key instances.
|
|
63
|
-
|
|
64
|
-
## Replacement Contract
|
|
65
|
-
|
|
66
|
-
Old API accepts any non-empty timezone string and returns a schedule or a domain
|
|
67
|
-
error. New API accepts only a timezone enum and throws on failure.
|
|
68
|
-
|
|
69
|
-
```text
|
|
70
|
-
old.Pre: nonEmpty(timezone)
|
|
71
|
-
new.Pre: timezone in KnownTimezone
|
|
72
|
-
|
|
73
|
-
old.Pre => new.Pre // false for a legacy but non-empty timezone
|
|
74
|
-
new.Post => old.Post // false if exceptions are not old domain errors
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
The replacement is unsafe for old callers even if current tests use only known
|
|
78
|
-
zones. Repair by adapting legacy strings, broadening the new precondition, or
|
|
79
|
-
making the break explicit.
|
|
80
|
-
|
|
81
|
-
## Temporal Model: Retried Payment
|
|
82
|
-
|
|
83
|
-
Snapshots do not distinguish a fresh approval from a duplicated response.
|
|
84
|
-
|
|
85
|
-
```text
|
|
86
|
-
states: Created | Authorizing(attempt, requestId) | Authorized(paymentId)
|
|
87
|
-
| Failed(reason)
|
|
88
|
-
initial: Created
|
|
89
|
-
|
|
90
|
-
Authorize(id): Created -> Authorizing(1, id)
|
|
91
|
-
Retry(id2): Authorizing(n, _) -> Authorizing(n + 1, id2)
|
|
92
|
-
Approved(id, payment):
|
|
93
|
-
Authorizing(_, id) -> Authorized(payment)
|
|
94
|
-
Approved(staleId, _):
|
|
95
|
-
Authorizing(_, currentId) -> unchanged when staleId != currentId
|
|
96
|
-
|
|
97
|
-
safety: authorization is recorded at most once
|
|
98
|
-
progress assumption: a live provider eventually responds and retries are finite
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
Verification needs stale, duplicated, reordered, and retry traces, not one test
|
|
102
|
-
per enum value.
|
|
103
|
-
|
|
104
|
-
## Proof Boundary: Quotient And Remainder
|
|
105
|
-
|
|
106
|
-
```text
|
|
107
|
-
qr(x, y) -> (q, r)
|
|
108
|
-
requires: x >= 0 && y > 0
|
|
109
|
-
ensures: q * y + r == x; 0 <= r < y; q >= 0
|
|
110
|
-
|
|
111
|
-
q = 0
|
|
112
|
-
r = x
|
|
113
|
-
while r >= y:
|
|
114
|
-
r = r - y
|
|
115
|
-
q = q + 1
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
Invariant: `q * y + r == x`.
|
|
119
|
-
|
|
120
|
-
- initialization: `0 * y + x == x`;
|
|
121
|
-
- preservation: `(q + 1) * y + (r - y) == q * y + r`;
|
|
122
|
-
- exit: the guard and invariant imply the required remainder relation;
|
|
123
|
-
- termination: non-negative integer `r` decreases by positive `y`.
|
|
124
|
-
|
|
125
|
-
The proof still assumes mathematical integer semantics and complete
|
|
126
|
-
postconditions. Overflow or a missing performance requirement can invalidate the
|
|
127
|
-
product claim without invalidating this proof.
|
|
128
|
-
|
|
129
|
-
## Constraint Propagation
|
|
130
|
-
|
|
131
|
-
Before a solver, a relation may itself be the design. Temperature conversion is
|
|
132
|
-
not inherently one-way:
|
|
133
|
-
|
|
134
|
-
```text
|
|
135
|
-
9 * celsius == 5 * (fahrenheit - 32)
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
A propagation network can accept either value, derive the other, forget a
|
|
139
|
-
retracted value, and reject inconsistent facts. Its model must identify
|
|
140
|
-
connectors, relations, who asserted each value, and conflict behavior. This is
|
|
141
|
-
useful when information may arrive from several directions; an ordinary
|
|
142
|
-
`toFahrenheit(celsius)` function is clearer when direction is fixed.
|
|
143
|
-
|
|
144
|
-
The core insight is that a relation states what values must agree, while a
|
|
145
|
-
procedure also chooses direction and evaluation. Do not import propagation
|
|
146
|
-
machinery merely to make a one-way calculation appear declarative.
|
|
147
|
-
|
|
148
|
-
## Constraint Solver: Shift Assignment
|
|
149
|
-
|
|
150
|
-
```text
|
|
151
|
-
variables: assigned(task) in Workers
|
|
152
|
-
hard constraints:
|
|
153
|
-
every task has exactly one worker
|
|
154
|
-
worker skill covers task requirement
|
|
155
|
-
overlapping tasks use different workers
|
|
156
|
-
objective: minimize total preference penalty
|
|
157
|
-
equivalence: assignments with equal penalty are acceptable
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
Test a known satisfiable fixture, a known impossible fixture, and two equal
|
|
161
|
-
optima. `unknown` or timeout is neither a solution nor proof of impossibility. A
|
|
162
|
-
bad weight can yield a mathematically optimal but operationally absurd plan.
|
|
163
|
-
|
|
164
|
-
## Logic Programming: Dependency Query
|
|
165
|
-
|
|
166
|
-
```text
|
|
167
|
-
depends(api, domain)
|
|
168
|
-
depends(ui, api)
|
|
169
|
-
|
|
170
|
-
reachable(a, b) if depends(a, b)
|
|
171
|
-
reachable(a, c) if depends(a, b) and reachable(b, c)
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
Query `reachable(ui, X)` should yield `api` and `domain`. State whether different
|
|
175
|
-
paths yield duplicate answers and how cycles terminate. If every product query
|
|
176
|
-
must terminate, a restricted deductive language may be better than a general
|
|
177
|
-
backtracking language.
|
|
178
|
-
|
|
179
|
-
## Planning: Rolling Server Upgrade
|
|
180
|
-
|
|
181
|
-
```text
|
|
182
|
-
state: set of Server(name, online, version)
|
|
183
|
-
initial: all online at version 1
|
|
184
|
-
goal: all online at version 3
|
|
185
|
-
invariant: at least one server is online
|
|
186
|
-
actions:
|
|
187
|
-
takeOffline(server) when another server remains online
|
|
188
|
-
upgrade(server) when server is offline
|
|
189
|
-
bringOnline(server)
|
|
190
|
-
cost: one per action, plus optional online-version-skew penalty
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
Show every intermediate state so the invariant can be checked. A shortest plan
|
|
194
|
-
under action count may not minimize risk; changing the cost model can legitimately
|
|
195
|
-
change the preferred plan. Valid and preferred plans are different claims.
|
|
196
|
-
|
|
197
|
-
## Selection And Stop
|
|
198
|
-
|
|
199
|
-
| Uncertainty | Artifact | Stop |
|
|
200
|
-
| --- | --- | --- |
|
|
201
|
-
| ambiguous rule | predicate + counterexample + cases | every partition has one result or visible policy gap |
|
|
202
|
-
| data integrity | relations + quantified constraints | known valid and invalid instances differ |
|
|
203
|
-
| compatibility | old/new pre/post implications | callers are covered or breaking scope is explicit |
|
|
204
|
-
| history/order | transition model + safety/progress | stale, retry, duplicate, reorder are defined |
|
|
205
|
-
| exhaustive implementation claim | contract + invariant/proof obligations | assumptions and remaining obligations are explicit |
|
|
206
|
-
| allocation/search | variables, constraints, objective | satisfiable, impossible, alternate-optimum fixtures behave as modeled |
|
|
207
|
-
| inference | facts, rules, query semantics | expected and cyclic cases are explained |
|
|
208
|
-
| action sequence | state, action, invariant, goal, cost | each intermediate state is valid |
|
|
209
|
-
|
|
210
|
-
## Source Trace
|
|
211
|
-
|
|
212
|
-
- Hillel Wayne, *Logic for Programmers*, version 0.14.0, May 4, 2026:
|
|
213
|
-
predicates, contracts and replacement, formal proof boundaries, relational
|
|
214
|
-
data and constraints, temporal models, solvers, logic programming, planning,
|
|
215
|
-
and answer-set reasoning. Examples are adapted for product modeling.
|
|
216
|
-
- Harold Abelson and Gerald Jay Sussman with Julie Sussman, *Structure and
|
|
217
|
-
Interpretation of Computer Programs*, Second Edition, MIT Press, 1996:
|
|
218
|
-
state, constraints, and explicit evaluation models.
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
# Abstraction Barriers And Closure
|
|
2
|
-
|
|
3
|
-
Use this reference to design a truthful level of language. A barrier separates
|
|
4
|
-
programs that *use* a concept from code that *represents* it. Closure determines
|
|
5
|
-
whether the concept's combination mechanism can build values at every useful
|
|
6
|
-
scale.
|
|
7
|
-
|
|
8
|
-
## Wishful Decomposition
|
|
9
|
-
|
|
10
|
-
Start with the result in domain vocabulary:
|
|
11
|
-
|
|
12
|
-
```text
|
|
13
|
-
checkout(cart, customer):
|
|
14
|
-
priced = priceCart(cart, customer.pricingContext)
|
|
15
|
-
payable = applyCredits(priced, customer.credits)
|
|
16
|
-
return authorizePayment(payable.total, customer.paymentMethod)
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
For each wished operation state:
|
|
20
|
-
|
|
21
|
-
```text
|
|
22
|
-
caller-visible result
|
|
23
|
-
normal and failure examples
|
|
24
|
-
details the caller should stop knowing
|
|
25
|
-
owner of validation/invariant
|
|
26
|
-
smallest replacement or behavior check
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
Wishful code exposes possible units; it does not prove they deserve public
|
|
30
|
-
interfaces.
|
|
31
|
-
|
|
32
|
-
## Build A Data Barrier
|
|
33
|
-
|
|
34
|
-
Use this construction rule:
|
|
35
|
-
|
|
36
|
-
1. Name the domain value and interpretation.
|
|
37
|
-
2. List only supported constructors, selectors, predicates, and domain
|
|
38
|
-
operations.
|
|
39
|
-
3. State laws callers may rely on.
|
|
40
|
-
4. Identify the one owner of validation, normalization, and simplification.
|
|
41
|
-
5. Write two materially different representations.
|
|
42
|
-
6. Rewrite one real caller using only the public vocabulary.
|
|
43
|
-
7. Search for remaining representation primitives outside the owner.
|
|
44
|
-
|
|
45
|
-
Worked rational-like value:
|
|
46
|
-
|
|
47
|
-
```text
|
|
48
|
-
Rate = conversion relationship between two quantities
|
|
49
|
-
|
|
50
|
-
makeRate(numerator, denominator)
|
|
51
|
-
numeratorOf(rate)
|
|
52
|
-
denominatorOf(rate)
|
|
53
|
-
multiplyRate(left, right)
|
|
54
|
-
|
|
55
|
-
law: denominatorOf(makeRate(n, d)) > 0
|
|
56
|
-
law: Rate(1, 2) and Rate(2, 4) have equal domain meaning
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
Representation A reduces at construction. Representation B stores raw terms and
|
|
60
|
-
reduces at selection. `multiplyRate` must not change between them. The barrier
|
|
61
|
-
preserves freedom to decide *when* normalization happens.
|
|
62
|
-
|
|
63
|
-
Reject the barrier when no choice is hidden, callers still require raw layout,
|
|
64
|
-
or the public operations are just field aliases with no stable laws.
|
|
65
|
-
|
|
66
|
-
## Procedures As Values
|
|
67
|
-
|
|
68
|
-
A higher-order boundary is justified when the varying role has a stable
|
|
69
|
-
contract.
|
|
70
|
-
|
|
71
|
-
```text
|
|
72
|
-
aggregate(items, base, project, combine)
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
Here `project` and `combine` are values the algorithm can receive without
|
|
76
|
-
knowing their bodies. Record their preconditions, effects, error behavior, and
|
|
77
|
-
cost assumptions. Passing a callback does not make hidden mutation or retries
|
|
78
|
-
irrelevant.
|
|
79
|
-
|
|
80
|
-
## Closure
|
|
81
|
-
|
|
82
|
-
Suppose a UI layout language has:
|
|
83
|
-
|
|
84
|
-
```text
|
|
85
|
-
Panel = Text(content) | Image(src) | Row(List<Panel>) | Column(List<Panel>)
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
`Row` and `Column` accept `Panel` values and produce `Panel`, so primitive and
|
|
89
|
-
compound panels combine uniformly:
|
|
90
|
-
|
|
91
|
-
```text
|
|
92
|
-
Column([
|
|
93
|
-
Text("Order"),
|
|
94
|
-
Row([Image("item.png"), Text("2 × mug")])
|
|
95
|
-
])
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
Closure check:
|
|
99
|
-
|
|
100
|
-
```text
|
|
101
|
-
unit predicate: what counts as Panel
|
|
102
|
-
closed constructors/combinators: Panel... -> Panel
|
|
103
|
-
observers/finalizers: Panel -> outside world
|
|
104
|
-
invalid nesting: combinations forbidden by product meaning or cost
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
Rendering is a finalizer `Panel -> Pixels`; pretending it is another `Panel`
|
|
108
|
-
would blur the boundary. Do not make every method chainable. Preserve closure
|
|
109
|
-
only for the central composition unit.
|
|
110
|
-
|
|
111
|
-
## Conventional Interfaces
|
|
112
|
-
|
|
113
|
-
A conventional interface lets independently designed stages exchange a shared
|
|
114
|
-
shape:
|
|
115
|
-
|
|
116
|
-
```text
|
|
117
|
-
enumerateOrders : Query -> Sequence<Order>
|
|
118
|
-
eligible : Sequence<Order> -> Sequence<Order>
|
|
119
|
-
invoice : Sequence<Order> -> Sequence<Invoice>
|
|
120
|
-
sum : Sequence<Invoice> -> Money
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
The shared sequence contract enables composition, but record whether stages are
|
|
124
|
-
eager or lazy, ordered or unordered, finite or unbounded, single-use or
|
|
125
|
-
replayable. “Iterable” alone may hide operationally incompatible processes.
|
|
126
|
-
|
|
127
|
-
## Barrier Review Artifact
|
|
128
|
-
|
|
129
|
-
```text
|
|
130
|
-
Domain meaning:
|
|
131
|
-
Use-level operations:
|
|
132
|
-
Representation-level operations:
|
|
133
|
-
Concrete representations A and B:
|
|
134
|
-
Laws and invariant owner:
|
|
135
|
-
Real caller rewritten:
|
|
136
|
-
Leak search:
|
|
137
|
-
Closure unit and closed operations:
|
|
138
|
-
Observers/finalizers:
|
|
139
|
-
Operational assumptions:
|
|
140
|
-
Decision or unresolved evidence:
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
## Failure Diagnosis
|
|
144
|
-
|
|
145
|
-
- A new representation changes every caller: the barrier is too low or leaked.
|
|
146
|
-
- Public operations mention JSON keys, indexes, providers, or library types: the
|
|
147
|
-
use level is contaminated by representation.
|
|
148
|
-
- A combinator result needs a second assembly API: closure is missing or the
|
|
149
|
-
units are not genuinely uniform.
|
|
150
|
-
- A closed API includes I/O as if it returned the same value world: split the
|
|
151
|
-
finalizer.
|
|
152
|
-
- A conventional interface hides eager materialization or ordering: add the
|
|
153
|
-
operational contract or choose a different interface.
|
|
154
|
-
|
|
155
|
-
## Source Trace
|
|
156
|
-
|
|
157
|
-
- *Structure and Interpretation of Computer Programs*, Second Edition,
|
|
158
|
-
sections 1.1-1.3 and 2.1-2.2: black-box procedures, wishful thinking,
|
|
159
|
-
higher-order procedures, data abstraction, abstraction barriers, closure, and
|
|
160
|
-
conventional interfaces.
|