This chapter is the reasoning behind the rules. It adds no rules of its own: the other chapters say what Captain does, and the decision records in the Captain specification say what was decided and what was rejected. Here is why, so that a future change does not undo a choice by accident.
Where Captain came from
Captain is a dialect of Zing, an earlier Frogfish language design. Zing was never built, but a great deal of design went into it, and it has donated to several dialects. Captain took from it:
- the message-language identity: keyword selectors with readable
argument labels (
download url: u sha256: d), bracket blocks, and control written as messages (ifTrue:,whileTrue:); - symbols (
#Running), tagged strings ("10.40.0.0/16"#cidr) and shapes (#( "a", "b" )); - protocols and instances;
- the lexical ground rules:
;;comments,::module paths,.to end a form,:=for assignment, the split betweenTypeNameandname, parenthesised member access, a closed set of operators with no unary minus; - and, most of all, its first principle, below.
Captain added what its job needed: quantities with units (8GiB, 5min,
85%, 500USD), effects, frontiers, plans, grants, receipts and secrets. It
dropped what it did not: Zing's C foreign interface, function types, and
receiver-binding procedure heads. Captain is not Zing, and no compatibility
is promised either way. When a language question comes up in Captain, Zing's
answer is read first and adopted where it fits. The type-directed conversion
n as: Decimal, from Zing's decision ZD-009, is one such adoption.
1. Machine-authored, human-read
Captain's main author is increasingly a machine, and people mostly read: they review programs, read plans and approve them by digest. Human authorship is welcome, but saving keystrokes is not the organising principle.
This favours explicit, predictable rules and visible boundaries. It does not mean verbose boilerplate everywhere. Where Captain infers something, such as a local's type from its first value, the rule is simple and local; across an interface (parameters, results, fields, effect signatures) everything is written down.
It also favours one obvious way to write each thing. A machine asked to
write a program will write the common form; a reviewer reading it should
recognise that form at once. A second spelling for the same operation is a
second thing to recognise, and a place for two programs that look alike to
differ. So Captain has append: and not also + for text, Option and not
also null, ret and not also an implicit last value.
2. Ordinary messages do ordinary work
Captain keeps Smalltalk's message style: xs forEach: [ :x | ... ],
a divide: b scale: 2 rounding: #HalfEven. A keyword selector names each
argument at the call site, so a reader never has to remember what the third
positional argument meant.
New capability arrives as messages and library procedures, not as new
syntax. Conversion is the message as: rather than a family of
width-specific functions; rounding is scale:rounding: rather than an
operator; typed JSON decoding is Json decode: text as: List[Item], with the
type passed as an ordinary argument. The grammar stays small, and every new
feature reads like the old ones.
When a word from Smalltalk is missing, the checker says what Captain calls
it. Captain looks like Smalltalk, so people and models write Smalltalk; a
help line that names forEach: for do: turns a confusing error into a
one-word fix.
3. A small core and a typed vocabulary
The runtime implements a small set of root effects natively: running a
program, an HTTP request, bounded file operations, observations and secret
resolution. Everything else (a wrapper around git or curl, a provider's
API, a deployment workflow) is ordinary Captain code built on those roots,
and ships as an ordinary module.
This keeps the trusted surface small: no library can widen what the runtime itself can do. And it keeps libraries honest: a wrapper's effects, tool requirements and failure modes are visible in its artifact's manifest like anyone else's.
4. Checked before it runs
A Captain program's effects are known before any of them happen. The checker
computes the effects each procedure can reach, refuses an effect called
where it is not available, and refuses a destructive step that lacks the
receipt or grant that makes it safe. Then captain plan shows every effect
an entry would perform, with its arguments, before anything runs.
Several rules exist for this alone:
- Blocks do not escape. A block runs only while the call it was passed to runs. The objection was never to anonymous code: it was to code whose lifetime and effects nobody can bound. A block that cannot be stored or returned has a place in the program where its effects happen, and a block sent to another machine has a capture list the plan can print.
- Plans are honest. When what happens next depends on a value only an effect can produce, the plan stops there and says so, rather than guessing. A plan never claims certainty it lacks.
- Exceptions do not exist. A failure is a value or the end of the run, never an invisible exit.
5. Determinism is the law
The same source always builds to the same bytes. The same artifact, with the same inputs and the same effect outcomes, always does the same thing. The only door to nondeterminism is the effect boundary, and every outcome that passes through it is recorded in the run log, so a run can be replayed from its log alone.
That is why the virtual machine has no clock, no randomness and no ambient environment, and why what ships is bytecode, never source: an artifact's digest names exactly one program, and a plan's digest names exactly one plan. Approval would mean nothing if either could drift.
6. Exactness is a promise
Every point where a number loses digits is written in the program, never
implied. There is no floating point. A decimal keeps every digit; / gives
the exact quotient or fails the run; rounding names its scale and its mode.
Integer and decimal meet only through as:. Quantities carry their
dimension, so bytes are never added to seconds and dollars never compared
with euros.
A calculation someone will audit has to be reproducible digit for digit, and a reviewer has to see where any digit was given up. A language that truncates silently in one place has broken that promise everywhere.
7. Authority is visible and unforgeable
Secrets, receipts and grants are types that no expression can make:
- a
Secretis a handle. The program moves the handle; the bytes go from the store straight to the effect that needs them, and never enter the virtual machine, a log or a diagnostic; - a
Receiptis evidence that an effect completed, minted by the runtime, so a step that requires a drained node cannot be given a pretend one; - a
Grantis authority, minted only by approving a plan, and bound to that plan's digest.
Destroying needs strictly more authority than creating: destructive effects demand grants, creative ones do not. A program written by a machine cannot grant itself permission, and a reviewer approving a plan knows exactly what authority they are handing over.
8. No agent on the other side
When a program works on another machine, Captain reaches it over SSH, with
the system's own client. The remote machine runs sshd and the tools the
program uses, and nothing of Captain. There is one orchestrator, on the
machine that holds the plan and the approval, and nothing to install,
upgrade or trust on every host.
9. Never dropped, never changed
Released formats and virtual-machine generations are kept for ever, and a generation's meaning never changes. When a decision changes what an operation does, as exact division did, the new meaning goes into a new generation; artifacts and run records made before it keep running and replaying exactly as they did. A run record is evidence, and evidence that changes meaning after the fact is not evidence.
This is also why changes are made slowly. A feature becomes part of Captain only when Captain's own direction or at least two of its own tools need it, when it keeps the checker's properties (closed nominal types, explicit conversion, effects known before they run), and when it is worth keeping for ever.
How to use this chapter
When you want Captain to do something it does not, ask:
- Would a reviewer reading the program see what it does, without knowing a rule the text does not show?
- Is there already one way to write it? Would this add a second?
- Can a library procedure or a message express it, instead of new syntax?
- Are its effects, its failures and the digits it drops all visible before it runs?
- Does it keep runs deterministic and replayable?
- Is it worth keeping for ever?
If the answers are yes, it may belong in Captain. If not, it usually belongs in a library, or in the host that runs Captain.