0Pricing
Zig Academy · درس

لا تدفق تحكم خفياً ولا عمليات تخصيص خفية

تعرّفوا إلى وعود التصميم التي تحدد Zig

لا تدفق تحكم خفياً ولا عمليات تخصيص خفية درس مجاني في Zig Academy على CoddyKit. هذا هو الدرس 3 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في 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/7) وفتح باقي دورة Zig Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Zig Academy 4 دروس في المجموع.

ماذا ستتعلم في «لا تدفق تحكم خفياً ولا عمليات تخصيص خفية»؟

تعرّفوا إلى وعود التصميم التي تحدد Zig تتمرن على Zig Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Zig Academy؟

لا تُشترط خبرة سابقة. Zig Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 4.

كم من الوقت يستغرق درس «لا تدفق تحكم خفياً ولا عمليات تخصيص خفية»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Zig Academy هذا؟

نعم. كل درس في Zig Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. ما المشكلة التي يحلها Zig؟
  2. Zig مقارنةً بـ C وRust وGo
  3. لا تدفق تحكم خفياً ولا عمليات تخصيص خفية
  4. ما الذي يمكنكم بناؤه باستخدام Zig
← العودة إلى Zig Academy