17 — Language of code and guards
Chapter 17 joins two topics that grew out of the same experience: what language we write code in and how to make rules survive a long session with an assistant. The common thought: a rule that lives only in someone’s head isn’t a rule, and a rule without a test is a wish. Below is what stands behind the rules.
Two readers, two languages
English code is the ecosystem’s language ↗
Every Repository (repo) — A store of the whole project’s code together with its full history of changes — who changed what and when. The repo is the project’s memory: code, documentation and change history in one place. more in the glossary → has two audiences, and each of its layers is written for one of them. Code — the names of modules, functions, variables, tests, tables, flags, configuration keys — is read by the machine, the search tool, the CI (continuous integration) — Automation that builds the project and runs the tests by itself after every change to the repository. A bug shows up minutes after the commit, not a week later in production. more in the glossary → output, every future programmer and the assistant. English is the language of the whole ecosystem here: every library, every error message, every answer on the internet and the data the assistant itself learned from. A native-language identifier is a word the tools have never seen, that autocomplete won’t suggest, and that the next person will spell three ways — with diacritics, without them, transliterated differently.
Prose — documentation, plans, comments, user-facing text — works the other way round. It’s read by the project owner, who thinks in their own language, and the why behind a decision loses precision in a second language. So the split follows the reader, not the mood, and it’s written down once, in two lines in CLAUDE.md (07).
Tests are code too
Tests are code. ↗
A test name is an identifier: the test runner prints it, CI searches for it, and a failure report at 3 a.m. consists of nothing else. The pattern test_<subject>_<condition>_<expectation> in English tells you at once what failed. The why behind the test — the incident, the date, the cost of the bug — goes into the docstring, in the prose language, where it belongs:
# before — hard to search for and hard to read
def test_koszt_wobec_zysku_NIE_ISTNIEJE_w_stratnym_oknie(conn): ...
# after
def test_cost_share_is_none_in_a_losing_window(conn):
"""30% empty values in the cost column from the 2026-09 measurement: the measure is cost / profit,
so in a losing window the denominator doesn't exist — the engine returns None on purpose."""
No mixed identifiers ↗
test_cost_NIE_ISTNIEJE_in_window is the worst of both worlds: you can neither read it comfortably nor predict which word to search for. The same rule covers test helpers and Fixture — Prepared data or state a test runs against (e.g. a small database with a few records). A test is only repeatable if it always starts from the same point. more in the glossary → — a fixture named szablon_bazy is a bilingual API — An agreed way for two programs to talk to each other — one asks, the other answers in a set format. Through an API your app connects to outside services (payments, maps, AI). Treat an API key like a password. more in the glossary → every user has to memorise.
Tool names stay names
Names a tool prints stay English inside prose ↗
Even in Polish text, Commit — A saved, labelled point in the project’s history — a confirmation of a specific batch of changes. Small, described commits make a history you can return to any working state from. more in the glossary →, --dry-run, migrate.py or the deploy-* tag stay in the original — because that exact form is what someone will search for. Translating a flag or a tag makes the description stop matching what the terminal shows. An ordinary word for the action itself can be in the prose language: the Polish edition writes “wdrożenie” (Deploy — Releasing a new version of the app “live”, where real people use it. It’s the moment a change reaches real people — which is why it happens only on an explicit “deploy”. more in the glossary →), but the tag is still called deploy-2026-11-20. That’s how the Polish edition of The Craft is written, and how this website is written.
Why rules need guards
A rule without a Guard — A test that enforces a project rule (e.g. “every module is in the AI_README”) and stops the commit when it’s broken. A rule without a guard is only a wish — a long session will break it in good faith. more in the glossary → is a wish. ↗
“Every directory has an AI_README — A map file in every code directory: what’s here, what it’s for and what to watch out for — written for search. The assistant finds the right file with one search instead of reading the whole directory. more in the glossary →, updated before the commit” has been a commandment of this doctrine since day one (01). In the reference project, one session nevertheless shipped 95 of 98 code commits without touching the Index (database) — A lookup in the database that makes searching instant instead of scanning everything in order. The first move for slow queries — like an index at the back of a book instead of reading 400 pages. more in the glossary →. Not out of malice: the assistant read the constitution, which points to the maps, but never opened the commandment that says update before committing. Documentation and naming rules compete with the task at hand — and lose every time, unless something red stops the commit. The only rules that survive a long session are the ones enforced by tests.
So the chapter comes with two ready-made guards in the pack’s guards/ directory. The index guard checks that every directory with code has an AI_README.md, that every module is named in it (a module missing from the index is invisible to the next session), that the file stays under a 20 kB ceiling (a bigger one stops being an index and becomes a novel — then you split the directory, not the file) and that the list of guarded directories guards itself. What it can’t do: judge whether a description is current. That stays with the writer — the guard removes only the worst failure, a missing entry. The language guard flags identifiers that look like the prose language: by function words (for Polish e.g. “nie”, “jest”, “bez”, “dla”) and by letter shapes (“rz”, “sz”, endings like “-anie”, “-owy”). It’s a heuristic, not a dictionary — some words will slip through, and English look-alikes are kept on an exception list.
pytest reference implementations ↗
Since version 1.1.2 the canon says it outright: the files in guards/ are written in pytest as a template. A Python — A popular, readable programming language — The Craft’s default for scripts, data and the back end. A proven default: lots of ready tools and libraries, easy to drive with AI. more in the glossary → project copies them; a Go, Rust, Kotlin or TypeScript project ports the same spec to its own test runner. The index guard needs only file globbing, and the language guard needs that language’s identifier parser or linter. The rule is the spec, not a particular Python file (08).
The ratchet: bringing a rule into old code
Plugging the language guard into an existing project immediately shows thousands of violations — the reference project started with 2,938 foreign identifiers in 129 files, almost all of them test names. Nobody will rewrite that in a day. The Ratchet — A way to bring a rule into old code: today’s state is frozen, and the number of violations can only fall. Nobody has to fix everything at once, but nobody adds new violations. more in the glossary → solves this.
Freeze ↗
Today’s count of violations in each file goes into a committed Baseline — A recorded “as of today” state — a measurement or a count of violations — later results are compared against. Without a reference point you can’t see whether things got better or worse — and in a ratchet it lets numbers only fall. more in the glossary → file. In a new project it’s empty.
New files must be clean ↗
The rule applies absolutely from the day it was written down — the old mess is tolerated, a new one isn’t.
Counts may only fall; ↗
Every touch of a file is a chance to reduce its violations; nobody has to rewrite two thousand names at once, but nobody may add the first one over the limit either. When a count falls, the baseline is lowered on command (--write-baseline), never silently — a baseline looser than the code would let old violations creep back without a word.
Raising a baseline by hand is weakening the guard ↗
Raising the number in the baseline to turn the test green is the same sin as disabling the test. The permission map puts it in the “never” column (06).
Exceptions are dated ↗
Sometimes an exception is justified — e.g. an oversized index waiting for its directory to be split. Then the exception has a date, a ceiling equal to today’s size (not more) and points to the backlog task that will remove it. An exception without a date or a task becomes a permanent part of the landscape.
So wiring the doctrine into an existing project takes one run of the guard, committing the baseline as it is, and a backlog entry “rename foreign identifiers — N left” with a concrete number. The number falls by itself over time, because every touched file has to get a little cleaner.