0Pricing
Zig Academy · Lesson

No Hidden Control Flow, No Hidden Allocations

The design promises that define Zig.

No Hidden Control Flow, No Hidden Allocations is a free Zig Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Zig Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Two Famous Promises

Zig is known for two rules: no hidden control flow and no hidden allocations. Together they make code easy to read and trust.

What Control Flow Means

Control flow is the order your code runs in. Hidden control flow is when calls happen that you cannot see on the page, surprising you later.

No Surprise Function Calls

Zig has no operator overloading and no hidden destructors. If a function runs, you can see its call right there in the source.

Failure Is Visible

There are no exceptions jumping across your program. To ignore or pass on a failure you write try or catch, so error paths are explicit.

const data = try readFile(path);

What Allocation Means

An allocation reserves memory for your data while a program runs. Hidden allocations are ones a language does for you, silently, behind a simple call.

Allocators Are Passed In

In Zig, code that needs heap memory takes an allocator as a parameter. If a function can allocate, its signature says so plainly.

fn loadConfig(allocator: std.mem.Allocator) !Config {
    // ...
}

You Choose the Strategy

Because you pass the allocator, you decide where memory comes from: a debug-checking one, an arena, or a fixed stack buffer.

Why This Helps You

Visible allocations make memory cost obvious, which is gold for performance tuning and for embedded targets that have no heap at all.

Reading Beats Guessing

These rules mean you reason about code by reading it, not by memorizing hidden machinery. What you see is what runs.

defer Makes Cleanup Clear

Cleanup is explicit too. A defer statement schedules code to run when the scope ends, so freeing memory sits right beside the allocation.

const buf = try allocator.alloc(u8, 64);
defer allocator.free(buf);

Trade-off: More Typing

The honest cost is a bit more typing: you thread allocators through your code. In return you get total clarity and control.

Quick Check

How do you know a Zig function might allocate memory?

Recap

No hidden control flow and no hidden allocations mean failures and memory are always visible. You read the code and know exactly what happens. ✨

Frequently asked questions

Is the “No Hidden Control Flow, No Hidden Allocations” lesson free?

Yes — the full text of “No Hidden Control Flow, No Hidden Allocations” is free to read here on the web, and the Zig Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Zig Academy course, upgrade to CoddyKit PRO.

What will I learn in “No Hidden Control Flow, No Hidden Allocations”?

The design promises that define Zig. You practise Zig Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Zig Academy?

No prior experience is required. Zig Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “No Hidden Control Flow, No Hidden Allocations” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Zig Academy lesson?

Yes. Every Zig Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. What Problem Does Zig Solve?
  2. Zig vs C, Rust, and Go
  3. No Hidden Control Flow, No Hidden Allocations
  4. What You Can Build with Zig
← Back to Zig Academy