hn.today

What Zig felt like, coming from Rust

besok.github.io149 points174 comments
Screenshot of What Zig felt like, coming from Rust

A Rust developer with seven years' experience reimplemented a JSONPath library (RFC 9535) in Zig to compare the languages. The experience highlighted a surprisingly thin IDE ecosystem for Zig, which pushed work back to the command line and made build.zig central for tasks like running unit tests, targeted tests, a compliance suite, and checks. Project layout favored a flat file structure: Zig nudges colocating related code in a few files rather than the deep module hierarchies common in Rust, which the author found simpler for medium-sized projects. Testing felt more verbose in Zig; inline tests are possible but integrating them with a flat layout required explicit build.zig wiring.

The biggest substantive difference was paradigm and memory management. Rust’s functional-friendly features - monadic error handling, iterators, immutability, and ownership - encourage pure transformations and eliminate classes of ownership bugs. Zig, by design, pushes in-place mutation and explicit allocator use, which forced different designs and manual bookkeeping. The author encountered real allocator-related bugs (leaks when errdefer was omitted, double-free from incorrect deinit ownership) and fixed them by adjusting defer placement and ownership transfer. The conclusion: Zig offers lower-level control and a simpler project surface at the cost of ergonomic functional abstractions and compile-time ownership guarantees, requiring careful manual memory discipline.

Read on besok.github.io174 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.