隠れた制御フローも隠れたメモリ確保もない
Zigを形作る設計上の約束を学びます。
「隠れた制御フローも隠れたメモリ確保もない」はCoddyKit上の無料Zig Academyレッスンです。 これはレッスン3/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはZig Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Zig Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
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. ✨
よくある質問
「隠れた制御フローも隠れたメモリ確保もない」レッスンは無料ですか?
はい。「隠れた制御フローも隠れたメモリ確保もない」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Zig Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Zig Academyコースには全4レッスンが含まれています。
「隠れた制御フローも隠れたメモリ確保もない」で何を学びますか?
Zigを形作る設計上の約束を学びます。 ブラウザで直接実行するハンズオンコードでZig Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Zig Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのZig Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン3/4です。
「隠れた制御フローも隠れたメモリ確保もない」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このZig Academyレッスンでコードを書いて実行できますか?
はい。すべてのZig Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- Zigはどのような問題を解決するのか
- ZigとC、Rust、Goの比較
- 隠れた制御フローも隠れたメモリ確保もない
- Zigで作れるもの