Best Practices
Let inference work
Section titled “Let inference work”Prefer := and save annotations for boundaries — public function signatures,
struct fields and places where the type is the documentation:
// Good: inference carries obvious typesnames := ["Ada", "Grace"]total := math.sum(scores)
// Good: annotations at the boundaryfunc price(count: int, each: float) -> float { count * each}Pipeline data, don’t nest it
Section titled “Pipeline data, don’t nest it”// Hard to scanprintln(str.to_upper(str.trim(input("Name: "))))
// Reads top to bottomname := input("Name: ") |> str.trim() |> str.to_upper()println(name)Name single-use closures instead of nesting map/filter three deep.
Match instead of if-chains
Section titled “Match instead of if-chains”// Fragile: silent fallthrough on new variants// Exhaustive: the compiler checks youmatch code { 0 => "ok", 1 => "retry", _ => "fail",}Propagate errors with values, not panic
Section titled “Propagate errors with values, not panic”// Good: caller decidesfunc load(path: str) -> Result<str, str> { match fs.read_file(path) { .ok(text) => .ok(text), .err(e) => .err("load {path}: {e}"), }}
// At the edge: unwrap once, loudlyconfig := load("app.conf").expect("app.conf is required")Reach for the stdlib first
Section titled “Reach for the stdlib first”String munging, math aggregation and encoding are already written, tested and shared by both runtimes:
import std.strimport std.math
slug := title |> str.replace(_, " ", "-") |> str.to_lower()best := math.max_arr(scores).unwrap_or(0)token := encoding.base64_encode(session)Browse the standard library before writing a helper.
Keep hot loops allocation-free
Section titled “Keep hot loops allocation-free”Prefer index loops and reuse buffers over chained temporaries in tight code,
then confirm with the benchmark harness in bench/ — ZZ beats Go most
clearly on allocation-heavy and concurrent workloads.
Iterate interpreted, ship compiled
Section titled “Iterate interpreted, ship compiled”zz run app.zz # fast feedbackzz check app.zz && zz fmt -c # gate in CI (exit 1 on issues)zz build -p app.zz # optimized native binary