Z031: Avoid underscore prefix in identifiers
Identifiers should not use underscore prefixes like _privateField or _helperFunction. This pattern, common in other languages to indicate privacy, is discouraged in Zig.
Examples
Bad
// expect: Z031
fn _privateHelper() void {}// expect: Z031
const _internalValue: u32 = undefined;Good
fn privateHelper() void {}const internal_value: u32 = undefined;
Single underscore for discarding values is allowed:
const _ = someFunctionWithSideEffects();
Double underscore prefix (for compiler/builtin internals) is allowed:
const __internal_value = 42;Rationale
From the Zig Style Guide:
In Zig, there are no private fields, and this style guide recommends against pretending otherwise. Instead, fields should be named carefully based on their semantics and documentation should indicate how to use fields without violating data invariants.
The underscore prefix convention from other languages (like Python's _private or C's __internal) doesn't translate well to Zig because:
- Zig has explicit
pubfor visibility - if something isn'tpub, it's already private to the module - Using underscores for "private" fields creates a false sense of encapsulation
- It makes names harder to read and type
- The underscore has a specific meaning in Zig: discarding values (
_ = x)
Instead of _helper, just use helper and don't export it with pub.