Lesson 3 of 9 · 25m
Examples That Work Are Product Features
Write realistic, runnable examples with expected output, complete context, and maintenance tests because copied examples become production behavior.
Readers do not paste your explanation into production. They paste your example. That makes every sample configuration, command, and request a small piece of shipped software. When an example is wrong, the cost is not embarrassment; it is a broken deployment at 2 a.m. or a customer who learns an insecure default because you taught it to them.
An example needs enough context to run
This is not enough:
hardline audit --config config.tomlWhich file? What does a minimal valid config look like? What output should appear? A better example gives a complete unit:
# hardline.toml
profile = "baseline"
[host]
hostname = "web-01"
user = "audit"
[guard]
revert_timer_minutes = 10hardline audit --config hardline.toml
# expect: 14 passed, 2 need review, report written to ./audit-report.htmlThe reader can now distinguish "I made a mistake" from "the example is wrong." Expected output is not decoration; it is a feedback mechanism.
Use realistic names and values
foo, bar, and example.com are fine for syntax sketches but poor for operational documentation. Realistic values teach conventions:
{
"hostname": "billing-api-2",
"environment": "production",
"owner": "payments-platform",
"alert_channel": "#payments-oncall"
}Do not use real customer names, internal addresses, live tokens, or production hostnames. Invented but plausible values are safer and more instructive than abstract filler.
Show the unsafe edge when it matters
Security documentation often needs a wrong example. Label it clearly and explain the failure:
# Unsafe: this trusts forwarding headers from any client.
rate_limit:
key: x_forwarded_for# Safer: the proxy overwrites the header before the application reads it.
rate_limit:
key: remote_addrA reader who copies the unsafe block after it is marked unsafe has at least been given a chance. A wrong block presented without warning is malpractice.
Keep examples synchronized with the product
Examples rot in predictable places: renamed flags, changed defaults, authentication requirements, response schemas, and UI navigation. The strongest defense is automated extraction or testing. If you cannot execute the sample, at least lint it:
python3 -m json.tool examples/create-workspace.json >/dev/null
hardline audit --config examples/minimal.toml --check-only
yamllint examples/docker-compose.ymlFor API examples, use fixture-backed contract tests. If the response shape changes, the documentation should fail before customers discover it.
Prefer one excellent example over five fragments
Fragments multiply ambiguity. A complete, narrow example beats a wall of partial snippets because the reader can inspect relationships: file layout, command order, permissions, inputs, outputs, and cleanup. Add variants only when the choice is common enough to deserve its own heading.
Field notes
- Never print a secret-shaped value that looks live; use obviously redacted placeholders such as
sk_live_REDACTEDonly when the format itself matters. - Include cleanup steps when examples create users, files, webhooks, DNS records, or cloud resources.
- Shell examples should use
set -euo pipefailwhen multi-line scripts can fail dangerously halfway through. - If a support ticket begins "I copied the docs exactly," treat it as a documentation defect until proven otherwise.
Was this lesson helpful?