0Pricing
Zig Academy · Pelajaran

Menyusun Proyek Multi-Berkas

Atur modul dengan rapi.

Menyusun Proyek Multi-Berkas adalah pelajaran Zig Academy gratis di CoddyKit. Ini adalah pelajaran 2 dari 4. Kamu bisa membaca pelajaran lengkapnya di bawah secara gratis — lalu praktikkan langsung di browser dengan editor kode bawaan dan tutor AI 24/7. Ini adalah bagian dari jalur belajar Zig Academy, dan progresmu tersinkronisasi di web dan aplikasi CoddyKit. Kursus Zig Academy mencakup 4 pelajaran total.

Bagian dari pelajaran ini belum diterjemahkan dan ditampilkan dalam bahasa Inggris.

One File Gets Crowded

As a program grows, a single main file turns into a wall of code. Splitting it into focused files keeps each part readable. 🗂️

main.zig Is the Entry

Your executable starts in main.zig, where the main function lives. It imports the other files and wires the program together.

const greet = @import("greet.zig");

Group by Responsibility

Put related code in one file: parsing in parser.zig, output in render.zig. Each file owns a clear responsibility and a small surface.

A File Is a Module

Since a file is a struct, importing it gives you a tidy module. Its pub functions and types form that module's public API.

const parser = @import("parser.zig");
const ast = parser.parse(input);

Use Folders for Scale

Group files into folders like src/net or src/cli. Import them with a relative path that includes the folder name.

const http = @import("net/http.zig");

Re-export from One Place

A small root file can re-expose pieces from several files, giving callers a single import that gathers the whole module.

pub const http = @import("http.zig");
pub const dns = @import("dns.zig");

Keep the API Small

Mark only what callers truly need as pub. Everything else stays private, so you can refactor internals without breaking other files.

Types Travel Too

Files export types, not just functions. A pub struct or enum in shapes.zig becomes shapes.Circle anywhere it is imported.

const shapes = @import("shapes.zig");
var c: shapes.Circle = undefined;

Watch for Cycles

Two files that import each other can form a cycle. Zig tolerates many cases, but a cleaner layout puts shared types in a third file.

Tests Live Beside Code

Each file can hold its own test blocks next to the code they check. Splitting files keeps related tests close to what they verify.

test "add works" {
    try std.testing.expect(add(2, 2) == 4);
}

Name Files Predictably

Use clear, lowercase file names that hint at the contents, like token.zig or config.zig. Good names make imports read almost like prose.

const config = @import("config.zig");

Quick Check

Recall how one file exposes its features to another.

Recap

You saw how to split code into focused files and folders, expose a small pub API, and even re-export through one root module. 🎯

Pertanyaan yang Sering Diajukan

Apakah pelajaran “Menyusun Proyek Multi-Berkas” gratis?

Ya — teks lengkap “Menyusun Proyek Multi-Berkas” gratis dibaca di sini di web. Untuk praktiknya secara interaktif (editor kode bawaan dan tutor AI 24/7) dan buka sisa kursus Zig Academy, upgrade ke CoddyKit PRO. Kursus Zig Academy mencakup 4 pelajaran total.

Apa yang akan aku pelajari di “Menyusun Proyek Multi-Berkas”?

Atur modul dengan rapi. Kamu berlatih Zig Academy dengan kode praktik yang langsung kamu jalankan di browser, dan tutor AI 24/7 menjawab pertanyaanmu saat kamu mengerjakan pelajaran ini.

Apakah aku perlu pengalaman untuk memulai Zig Academy?

Tidak diperlukan pengalaman sebelumnya. Zig Academy di CoddyKit dirancang untuk pemula hingga pelajar tingkat lanjut, jadi kamu bisa memulai di sini atau dari awal dan belajar sesuai kecepatan kamu sendiri. Ini adalah pelajaran 2 dari 4.

Berapa lama pelajaran “Menyusun Proyek Multi-Berkas” memakan waktu?

Sebagian besar pelajaran CoddyKit memakan waktu sekitar 5–10 menit. Setiap pelajaran ringkas dan interaktif, jadi kamu membuat kemajuan stabil dan melanjutkan dari tempat kamu tinggalkan di web dan aplikasi.

Bisakah aku menulis dan menjalankan kode dalam pelajaran Zig Academy ini?

Ya. Setiap pelajaran Zig Academy menyertakan editor kode bawaan, jadi kamu menulis dan menjalankan kode nyata langsung di browser dan mendapatkan umpan balik AI instan — tidak diperlukan penyiapan lokal.

Semua pelajaran dalam kursus ini

  1. Mengimpor Berkas dengan @import
  2. Menyusun Proyek Multi-Berkas
  3. build.zig.zon dan Pengelola Paket
  4. Menambahkan Modul Pihak Ketiga
← Kembali ke Zig Academy