ZI

Zig Defaults

Core Zig coding conventions

Details

Language / Topic
zigZig
Category
Style Guide

Rules

balanced
- Use `camelCase` for functions and local variables, `PascalCase` for types and structs, and `SCREAMING_SNAKE_CASE` for compile-time constants.
- Prefer `const` over `var` for all values that do not need to be mutated — immutability is the default and makes data flow easier to reason about.
- Use `@import("std")` at the top of every file and alias it as `const std = @import("std");` — always qualify stdlib calls with `std.`.
- Write functions to return error unions (`!T`) explicitly: `fn readFile(path: []const u8) ![]u8` communicates fallibility in the type signature.
- Use comptime parameters (`comptime T: type`) instead of runtime polymorphism to achieve zero-cost generic abstractions.
- Keep struct fields ordered from largest to smallest alignment to minimize padding and reduce struct size automatically.
- Use `std.debug.assert` for invariants that must hold in debug builds and document why each assertion is correct.