docs(system): deepen standard library research per topic
12c10600da25db8ef1ab280cae8f41948d2955b5
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
- Parent 1: ce1aa6a6f3aa
There are many coding harnesses - but this one is fast
12c10600da25db8ef1ab280cae8f41948d2955b5
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
+151 / −29 text lines
+151 / −29 text lines
Grounding for the `smith:plugin` world: extract the core of wisdom from respected standard libraries, adapted to a wasm component guest surface.Grounding for the `smith:plugin` world: deep lessons from respected standard libraries, adapted to a wasm component guest surface.| library | extract | reject or guard ||---|---|---|| [Lua 5.4](https://www.lua.org/manual/5.4/) | minimal surface, pragmatic verbs, one obvious way | thin mirror of Unix/C; no host OS vocabulary leaks into guests || [Java stdlib](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/module-summary.html) | completeness through orthogonal primitives, documented contracts | irre removable mistakes: deprecate-and-delete discipline from day one; additive-only worlds (already WASM0001 law) || [Go stdlib](https://pkg.go.dev/io) | scope discipline: each package answers one question; io.Reader/Writer as tiny universal contracts | inhomogeneous conventions between packages; one naming and error grammar across the whole world || [Zig std.io](https://zig.guide/standard-library/io) | composable Reader/Writer, explicit buffers, performance as a design constraint | young and messy: no feature enters the world without two real consumers || [Elm core](https://package.elm-lang.org/packages/elm/core/latest/) and the [style guide](https://elm-lang.org/docs/style-guide) | naming, organization, intuitiveness: `List.map` over `List.applyMappingFn`; small total surface; impossible-to-misuse functions; whole-ecosystem coherence | paradigm: no typeclasses in WIT; emulate composability with plain functions over records, not generics || [Rust std](https://doc.rust-lang.org/std/) | vocabulary types (Option/Result shapes → explicit result variants in WIT), coherence, [API guidelines](https://rust-lang.github.io/api-guidelines/) checklist discipline | allocator and OS assumptions: guests get linear memory and host-provided effects only; no ambient std assumptions in world design || [OCaml modules](https://ocaml.org/manual/modules.html) | published interfaces, many implementations, explicit binding | not an API-shape lesson: it is the plugin ecosystem model — already spec'd as module contracts with zero/one/many implementations and major-version binding |Facts:- Entire stdlib is roughly twenty tables; the language plus libraries implement in the order of tens of thousands of lines.- Design motto from the authors: provide mechanisms, not policies; libraries stay embeddable and host-agnostic in intent.- `io` mirrors C `stdio` (`FILE*` handles, `read` with format verbs); `string.format` mirrors `printf`; `os` exposes `execute`, `getenv`, `date`.- Sources: [Lua 5.4 manual](https://www.lua.org/manual/5.4/), [The Evolution of Lua (HOPL)](https://www.lua.org/doc/hopl.pdf).Extract:- Mechanisms-not-policies is the deepest fit: the host exposes typed primitives, plugins compose policies. No world interface should encode a workflow.- A total surface teachable in one sitting. Budget: every world interface should fit on one page.Reject:- The C-mirror: printf verbs, stdio metaphors, 1-based indexing. Guest APIs must speak component-model vocabulary (records, resources, results), never host-history vocabulary.- Ambient OS reach (`os.*`): already impossible under the sandbox; keep it impossible in world design, not just engine config.## Java — contracts, cruft, and the cost of foreverFacts:- `java.util.Date`: mutable, timezone-hostile, mostly deprecated for decades with no removal path. `Stack extends Vector`, `Properties extends Hashtable`: inheritance as API surface locking in implementation detail.- `Enumeration`→`Iterator`, `Observer`/`Observable` removed in 9, `Optional` arriving decades after null: corrections layered onto unremovable mistakes.- Counterexample inside the same stdlib: the Collections Framework — interfaces (`List`, `Map`, `Set`) separated from implementations (`ArrayList`, `HashMap`), each with documented complexity contracts. It stayed good because the seam was interfaces, not classes.- Source: [Java SE API](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/module-summary.html).Extract:- Interface/implementation separation at the collection level is the same seam as plugin module contracts: publish the contract, swap the implementation.- Documented behavioral contracts (complexity, thread-safety, nullity) as first-class API surface.Reject:- Inheritance as extension mechanism: world guests get composition only.- Mutable default types: every world record is a value; mutation belongs to resource handles with explicit methods.- The forever-deprecated zombie layer: deprecations must carry a replacement and a removal path from day one (already WASM0001 world-versioning law).## Go — one-method contracts, one grammarFacts:- `io.Reader` and `io.Writer` are single-method interfaces; nearly all byte flow in the ecosystem composes through them.- Proverb canonized by the designers: the bigger the interface, the weaker the abstraction.- `context.Context` threaded through every cancellable call after 1.7: cancellation became an explicit parameter, retrofit cost enormous.- Inhomogeneity is real: errors as values here, booleans there; per-package conventions drift despite `godoc` uniformity.- Sources: [io package](https://pkg.go.dev/io), [Go proverbs](https://go-proverbs.github.io/).Extract:- Single-purpose contracts: prefer several one-function WIT interfaces over one wide one; guests implement what they use.- Cancellation as an explicit parameter of every long-running world function — matches our budget and abort laws.- Uniform documentation grammar across the entire world: same section order, same terminology, machine-checkable.Reject:- Implicit interface satisfaction (not expressible in WIT regardless).- Convention drift between packages: one naming and error grammar for the whole world, reviewed mechanically.## Zig — explicit allocation, compositional performanceFacts:- `std.io.Reader`/`Writer` compose through duck-typed vtable structs; the 2024 IO redesign generalizes composition further and is still settling — the library is young and messy by its own admission.- Allocation is an explicit parameter everywhere; nothing allocates behind your back; buffers are passed, not grown implicitly.- Error sets are explicit unions in signatures; performance is a stated design constraint of the API shape itself.- Source: [Zig io guide](https://zig.guide/standard-library/io).Extract:- No hidden allocation or copying: every world function that moves bytes takes explicit bounds and buffer parameters.- Error sets as precise enumerated failure vocabularies — resist collapsing failures into one `error` case.- Performance belongs to the contract: batched calls, explicit budgets (our fuel and invocation budget are the same doctrine).Reject:- Duck typing via `anytype`: unavailable in WIT; composability must come from shared record types.- The churn of a young redesign: pin the world early, evolve additively, never mid-stream reshape.## Elm — naming discipline, mechanical semverFacts:- Core is around ten modules; the whole API fits in a practitioner's head. Argument order conventions exist and hold: data first, function last (`List.foldl fn acc list`).- The style guide bans abbreviations and presumes nothing: names say what they mean, consistently, across the entire ecosystem.- `elm/package` enforced semantic versioning mechanically: publishing computed the API diff and derived the version bump — breaking changes could not masquerade as patches.- `Json.Decode` makes untrusted payload parsing an explicit typed pipeline; nothing decodes implicitly.- Sources: [elm/core](https://package.elm-lang.org/packages/elm/core/latest/), [style guide](https://elm-lang.org/docs/style-guide).Extract:- Data-first parameter ordering for every world function; the convention is free until violated once.- No abbreviations; one glossary for the whole world, enforced in review.- Mechanical semver from API diff is directly transplantable: `smith plugin check` should diff worlds and classify additive versus breaking, feeding the world-version law instead of trusting authors.- Explicit typed decoding of untrusted provider payloads — already our provider law; the world should expose decode helpers, not implicit conversions.Reject:- Purity guarantees: paradigm does not transfer; reachability of effects transfers instead (capability grants).## Rust — layering, prefix grammars, checklist disciplineFacts:- `core`/`std` split: the always-available substrate versus the fuller environment layered above.- Naming grammar is codified: `as_` borrowed conversions, `to_` expensive copies, `into_` consuming conversions; `#[must_use]` marks effects ignoring-is-a-bug.- The [API guidelines](https://rust-lang.github.io/api-guidelines/) are a mechanical review checklist: casing tables, doc examples that compile and run, no panics in public API, no `unwrap` in shipped code.- Coherence rules keep impls from colliding ecosystem-wide.- Source: [std docs](https://doc.rust-lang.org/std/), [API guidelines](https://rust-lang.github.io/api-guidelines/).Extract:- Two-layer world: a core world every plugin sees, plus granted capability interfaces layered on top — the exact analogue of `core`/`std`, and it matches WASM0001 imports-with-grants law.- Prefix grammar for world function names; adopt one and hold it.- A written API-guidelines checklist for the smith world, applied to every world change, with compiling doc examples in the SDK.Reject:- Allocator assumptions baked into API shapes: guests own linear memory; world signatures express ownership by structure (values in, values out, handles by resource).## OCaml — signatures as the ecosystem unitFacts:- `.mli` interface files make the signature a first-class authored artifact; implementations seal against them explicitly.- Functors parameterize modules over modules; the ecosystem (opam) publishes packages whose value is the interface, with competing implementations ( MirageOS protocol providers are the canonical family ).- Source: [OCaml modules manual](https://ocaml.org/manual/modules.html).Extract:- Interface-first authoring: a plugin's manifest and world exports are authored like an `.mli` — the contract is the product, the implementation is replaceable.- This is already SPEC0001 law (module contracts, zero/one/many implementations, major-version binding); the research reinforces it: the binding model is the ecosystem's load-bearing wall, not a convenience.1. Minimal total surface; every interface must justify itself against two real consumers before entering the world.2. One naming grammar, one error grammar, one documentation shape across all interfaces — homogeneity is a feature.3. Tiny universal contracts (Reader/Writer shapes) over wide interfaces; compose in guests, not in the host world.4. Explicit over implicit: buffers, bounds, cancellation, and provenance are parameters, never ambient state.5. Vocabulary types with impossible-to-misuse constructors; result variants name failure precisely.6. Additive-only evolution; deprecations need a replacement and a removal path from the first release.7. Performance is part of the contract: batched calls, explicit budgets, no hidden allocation or copying requirements.8. Ecosystem over API: interfaces are publishable module contracts; implementations are swappable and bound explicitly.## Mapping notes- WIT has no generics: Zig/Go composability becomes plain functions over shared record types and resource handles.- Elm intuitiveness transfers directly to naming and organization review.- Rust API guidelines become the review checklist for every world change.- The OCaml lesson is already law in SPEC0001 (Discovery and modules); this research reinforces it, does not replace it.1. Minimal total surface; every interface needs two real consumers before entering the world (Zig, Lua).2. One naming grammar, one error grammar, one documentation shape across all interfaces (Go, Elm).3. Tiny universal contracts over wide interfaces; several one-function interfaces beat one fat one (Go, Zig).4. Explicit over implicit: buffers, bounds, cancellation, provenance are parameters, never ambient state (Zig, Go).5. Vocabulary types with impossible-to-misuse constructors; precise enumerated failure sets (Rust, Zig).6. Additive-only evolution; every deprecation carries a replacement and removal path (Java, WASM0001).7. Performance is part of the contract: batched calls, explicit budgets (Zig, our fuel law).8. Two-layer world: core plus granted capability interfaces (Rust `core`/`std`).9. Data-first parameter order; no abbreviations; one glossary (Elm).10. World version bumps are computed from API diffs, not asserted by authors (Elm mechanical semver).11. Interfaces are the ecosystem unit: contracts publish, implementations swap, binding is explicit (OCaml, Java Collections).12. Mechanisms, not policies: no world interface encodes a workflow (Lua).- The Evolution of Lua — <https://www.lua.org/doc/hopl.pdf>- Java SE API — <https://docs.oracle.com/en/java/javase/21/docs/api/java.base/module-summary.html>- Go proverbs — <https://go-proverbs.github.io/>- Elm core and style guide — <https://package.elm-lang.org/packages/elm/core/latest/>, <https://elm-lang.org/docs/style-guide>- Rust std and API guidelines — <https://doc.rust-lang.org/std/>, <https://rust-lang.github.io/api-guidelines/>- Do Reader/Writer-style byte contracts belong in the world at all, or only in the HTTP and stream interfaces where chunks already flow?- Which failure vocabulary granularity survives WIT result variants before becoming Java-style exception taxonomies?- How do module contracts compose with world versioning: are plugin-published interfaces worlds of their own?- Do Reader/Writer-style byte contracts belong in the world, or only inside HTTP and stream interfaces where chunks already flow?- Which failure vocabulary granularity survives WIT result variants before becoming a Java-style exception taxonomy?- How do plugin-published module contracts compose with world versioning: are they worlds of their own, or interface resources inside the smith world?- Can `smith plugin check` diff worlds mechanically today (wasm-tools), or does the tooling gap force author-asserted versions initially?