Keine verborgenen Kontrollflüsse, keine verborgenen Allokationen
Die Designversprechen, die Zig ausmachen.
Keine verborgenen Kontrollflüsse, keine verborgenen Allokationen ist eine kostenlose Zig Academy-Lektion auf CoddyKit. Dies ist Lektion 3 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Zig Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Zig Academy-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
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. ✨
Häufig gestellte Fragen
Ist die Lektion „Keine verborgenen Kontrollflüsse, keine verborgenen Allokationen“ kostenlos?
Ja — der vollständige Text von „Keine verborgenen Kontrollflüsse, keine verborgenen Allokationen“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Zig Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Zig Academy-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Keine verborgenen Kontrollflüsse, keine verborgenen Allokationen“?
Die Designversprechen, die Zig ausmachen. Du übst Zig Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um Zig Academy zu starten?
Keine Vorkenntnisse erforderlich. Zig Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 3 von 4.
Wie lange dauert die Lektion „Keine verborgenen Kontrollflüsse, keine verborgenen Allokationen“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser Zig Academy-Lektion Code schreiben und ausführen?
Ja. Jede Zig Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Welches Problem löst Zig?
- Zig im Vergleich zu C, Rust und Go
- Keine verborgenen Kontrollflüsse, keine verborgenen Allokationen
- Was Sie mit Zig erstellen können