How to write here
The writing rules for pages that both a person and a language model have to be able to trust, with the reason behind each one.
Diese Seite gibt es noch nicht auf Deutsch, deshalb steht sie hier auf Englisch. Zur englischen Seite
A page here is read by a person who wants an answer and by a model that will copy what it reads. Both need the same thing: one claim per sentence, the exact spelling of everything in code font, a number wherever there is a limit, and an example before the prose. These rules are the mechanically enforced ones plus the ones a reviewer checks.
Example#
The shape of a rule, in the form every reference page uses.
3. **A `const` binding is deep.** Through a `const` binding nothing changes: no reassignment, no field assignment and no
`var fn` method. `const` on a `List` therefore means the list never changes, not that the binding cannot be
reassigned.
```trb
const fixed = [1, 2]
```
```trb error
const fixed = [1, 2]
fixed.append 3
// error: `append` needs a `var`. Did you mean `appended`?
```Bold claim, then the rule in one or two sentences, then the example that shows it, then the mistake it prevents with the diagnostic quoted exactly.
Syntax#
Six things about the mechanics of a page.
- No
#heading in the body. Thetitleof the front matter is the heading of the page. The body starts at##. - Sentence case headings, no full stop and no colon at the end.
## What this is not, not## What This Is Not:. - Heading levels are never skipped. A
##is followed by a###at the deepest. - A heading that another page links to carries an explicit anchor:
## A long heading {#short-anchor}. Then rewording the heading does not break the link. - A code block is fenced with backticks and names its language:
trb,text,console,json,md,yamlordiff. Three backticks are the normal fence; a block that contains a fence itself opens with four. An indented code block and a tilde fence are not part of the format, because neither names a language and a block whose language is unknown is a block nothing verifies. - Links are inline:
[text](target)or[text](target#anchor). A reference link ([text][label]) splits the target away from the place it is used, which is what a chunked reader loses first.
Rules#
Terminology#
- One term per thing, and the glossary decides which. Write binding for a
constor avar, never variable. Write case for a variant of atype, never enum case or variant. Write command call for a call without parentheses. A second word for one thing costs a reader a lookup and costs a retrieval system the ability to find the chunk at all: a term that is not in a chunk cannot retrieve it. - Define or link every term at its first use on the page. A page is read alone. There is no
see above, noas we sawand nothe type from the previous section, because the previous section may not have been loaded. - Repeat the noun instead of writing a pronoun across a paragraph boundary.
The binding decidesbeatsIt decides.
Precision#
- Every rule is testable. A sentence that cannot be turned into a program that passes or fails is not a rule, it is a feeling. Number the rules of a reference page so that a reader, a reviewer and an error message can name one.
- State defaults and limits as numbers.
The stack check keeps 128 KiB of the stack in reserve, notthe stack check keeps some room. - No hedges. The words
usually,simply,obviously,basically,easily,of course,as mentioned,see above,and so on,please noteandetc.are rejected by the checker. If something holds under a condition, name the condition. If it holds always, say always. - Quote an error message exactly, character for character, in code font. Somebody will search for it. Run the code and copy what the compiler prints.
- Mark what does not exist yet. A feature that is designed but not implemented lives on a page with
status: plannedand the planned banner, or it is not written about. Astablepage that mentions a planned feature says so in the sentence and links the planned page. - Name the source. A
referenceorpackagepage lists insourcewhich section ofCONCEPT.mdor which file ofstd/it was derived from. That is how a page is found again when the language moves.
Examples#
- The example comes before the prose. A reference page opens with
## Example: the smallest complete program that shows the construct, before a word of explanation. Examples convey style and level of detail better than descriptions do. - Every
trbblock is verified by the compiler. By default it has to parse and be in the formatter canon. Ask for more or less in the info string:trb checktype checks it against the realstd/,trb runalso builds and runs it and compares the output with its// printscomments,trb fragmentis a signature rather than a program,trb erroris wrong on purpose and names every diagnostic it produces,trb exerciseis the starting code of an exercise in a lesson,trb skip <reason>is verified by nothing and the reason is printed by the gate. A claim about what a program prints belongs in atrb runblock, not in the prose around it. See the checks. - A wrong example is always paired with the right one, and the right one comes first. A bare prohibition loses
against what a model already believes; a correct line next to the incorrect one does not. This is why
## What this is notis a required section of every reference page. - Contrast with the language a reader is coming from where it prevents a wrong guess. One sentence in place
(
In Rust this would be a borrow; here it is a copy) plus a link to the contrast page.
TorbScript in a snippet#
- Follow the formatter canon. A call is a command wherever the grammar allows it (
Ok value,return Fail problem,const role = Role name,names.map Role) and has parentheses everywhere else: nested (Ok Some(x)), without arguments (list.length()), with an operator at the top level of an argument (assert(sum == 3)), over several lines, and in the head of anif,for,whileormatch. The checker enforces both directions. - No semicolons, and never two statements on one line. A statement ends at the end of its line.
- A multi-line
"""string is indented two spaces deeper than the line its statement starts on, with a closing"""that stands alone aligned with the content. - An imported case is bare, everything else keeps its dot.
None =>andSome(value) =>in a pattern, because the prelude imports them;.Circle(radius) =>for a case that is not imported. In an expression the same rule holds, andShape.Circle(1.0)is written out where nothing says which type is meant. - A snippet is complete enough to be true. A
trbblock is a whole file, so a snippet that needs an import writes the import. Where that would drown the point, usetrb fragmentand say in the prose what surrounds it.
Tone#
- Second person, present tense, active voice.
You writeandthe compiler reports, notit will be reported. - Say why, do not raise the volume. A rule with its reason is followed; a rule in capital letters is argued with. If a rule keeps being broken, the fix is a better example, not a louder sentence.
- No dates and no
currently. A page says what is true;statussays how far it can be trusted. A superseded approach belongs inexplanation/as a decision, not in a reference page as history.
What this is not#
A page is not a narrative. This is a page that has to be read from the top:
Now that we have seen how bindings work, let us look at what happens when we try to change one. As you might expect,
the compiler will usually complain. Let us try it and see.This is the same content as a page:
## Rules
1. **A `const` binding cannot be reassigned, and nothing below it can be changed.** `const` is deep: assignment to a
field and a call of a `var fn` method are both errors through a `const` path.The first one costs a reader three sentences to reach the rule and gives a retrieval system nothing to match. It also
contains usually, which the checker rejects.
A summary is not the first paragraph. The summary lives in the front matter and is read in a list. The first
paragraph of the body is written for somebody who has already opened the page, and it may repeat the summary's claim in
more words.
A reference page is not a place to argue. One sentence of reason is welcome next to a rule; the argument belongs in
explanation/. The reverse holds too: an explanation page does not restate the syntax, it links it.
A "how to" page is not a tutorial. A tutorial has one path and no branches, and it is in guide/. A how-to assumes
competence, forks where the reader's situation forks, and is titled with the verb (Read a file, not
How to read a file).
Related#
- How this documentation is structured - the tree, the kinds and the required sections.
- The front matter - the fields and their rules.
- Adding a page - the templates.
- The checks - which of these rules a command decides.
- The glossary - the normative terms.
- The formatter canon - the call style every snippet follows.