← Thu, Nov 5 digest

Partial Operator Precedence

read article ↗ hn thread ↗

Zig implemented partial operator precedence to require explicit parentheses for ambiguous operator combinations and reduce cognitive load.

read it Systems programmers and Zig users will benefit from diving into these detailed changes, particularly the new operator precedence rules and ArrayList memory safety updates.

summary

Zig's latest devlog introduces partial operator precedence, requiring explicit parentheses for ambiguous operator expressions to prevent bugs. It also relocates all package management logic from the compiler binary into the build maker process, reducing binary size and improving safety. Additional updates include pointer stability locking for std.ArrayList and major progress on the SPIR-V shader backend.

key points

  1. Ambiguous operator combinations like mixing orelse and == now trigger compiler errors unless explicitly parenthesized, with an automated upgrade path via zig fmt --upgrade.
  2. Package management, networking, and fetching logic have been moved out of the compiler executable into the independent maker process, shrinking binary size by 4%.
  3. std.ArrayList now supports pointer stability locks via lockPointers() to catch memory safety violations when underlying buffers resize.

who should read it

Zig developers and systems programmers interested in language design and compiler internals.

discussion warm

consensus

Commenters strongly praise the partial operator precedence decision, with many arguing that complex operator precedence tables are an unnecessary source of confusion and bugs.

pushback

A minority of commenters argue that programming languages should eliminate operator precedence entirely in favor of strict left-to-right evaluation or explicit function calls.

best comment by raphlinus ↗

Worth noting, WGSL does this too, and is mostly a bit stricter than Zig: `a + b & c` and `a << b & c` are errors in WGSL but accepted by Zig. (Quick: off the top of your head, how do those parse)?

I'm thinking of doing this for symbolasm also.

It adds valuable context by noting that WGSL enforces an even stricter approach to partial operator precedence than Zig.

Generated by an LLM from the article and thread. Check the sources before relying on it.