HN
Today

Four Months of Zig

This Hacker News favorite offers a developer's four-month journey with Zig, dissecting its distinctive design choices like explicit allocators and comptime while candidly addressing its current growing pains like instability and documentation. The community dives deep into these architectural philosophies, particularly contrasting them with Rust, sparking spirited debate on "low-level control" versus "developer convenience."

86
Score
51
Comments
#9
Highest Rank
12h
on Front Page
First Seen
Oct 27, 9:00 PM
Last Seen
Oct 28, 8:00 AM
Rank Over Time
15109111323182419242121

The Lowdown

Anna Liberty shares her experiences after returning to the Zig programming language for four months, detailing what she appreciates and what she hopes to see improved. She used Zig for projects like snurl (a smallnet library) and attended a local "Zig Day," highlighting the vibrant community and the opportunity to interact with Zig's creator, Andrew Kelley. Her reflections frequently draw comparisons to Rust, her previous language of choice, offering insights into Zig's unique approach to systems programming.

Here are the key takeaways from her experience:

  • Likes:
    • anyzig: A tool that simplifies switching between different Zig versions.
    • Explicit IO and Allocators: Appreciates the clarity and control this provides, contrasting it favorably with Rust's implicit allocations and testing difficulties.
    • comptime: Praises its seamless metaprogramming and precomputation capabilities.
    • Build System: Finds Zig's build system stellar and flexible, capable of integrating with other tools.
    • Dependency Culture: Values Zig's ethos of minimizing dependencies, leading to smaller, more auditable codebases, unlike Rust's often large dependency trees.
    • Error Handling: Believes Zig's error handling encourages correct behavior by default, avoiding the panics often seen in Rust.
    • Incremental Compilation: Highlights the fast, "human perception" speed of Zig's incremental compilation, which significantly improves workflow compared to Rust.
  • Desired Improvements:
    • Improved Stability: A common desire for Zig's standard library to stabilize before 1.0, acknowledging the current breaking changes.
    • Lifetime Support: Wishes for better compiler assistance with lifetimes to prevent common pitfalls with local variables.
    • More Documentation: Notes the sparse documentation and the reliance on community engagement for knowledge.
    • comptime Allocators: Hopes for compile-time allocators to enable things like JSON parsing at build time.
    • Better Bootstrapping: Addresses the current challenge with Zig's self-hosting compiler, which prevents full source bootstrapping for distributions like Debian.

Liberty concludes by reaffirming her commitment to Zig, finding no other language she prefers more, despite its current shortcomings. She plans to continue using it for most projects and contribute more to its development.

The Gossip

Allocator Antagonism & Adherence

A significant debate revolves around Zig's explicit allocator philosophy. Proponents, like the author, praise the granular control and clarity it offers, especially for testing and resource management in systems programming or server contexts (e.g., arena per request). Detractors argue it adds unnecessary complexity for most applications, preferring higher-level abstractions like RAII (Rust/C++) or simply `malloc` for ease of use, and pointing out potential footguns with arenas or where `malloc` might even be faster (e.g., `mimalloc`). Some also note the "firm stance against implicit logic" in Zig, which leads to this explicit design.

Stability Scrutiny & Speedy Progress

Many commenters echo the author's sentiment regarding Zig's instability and breaking changes while it approaches 1.0. Users express excitement for the language's potential but find the current flux a significant blocker for adoption in stable projects. There's an underlying recognition that this instability is part of its rapid development, but a strong desire for a stable release persists.

Error Handling: Simplicity vs. Specificity

The article's comparison of Zig's error handling to Rust's `Result` type sparked a direct rebuttal. While the author implies Rust's `Result` with `Box<dyn Error>` is cumbersome, commenters clarify that Rust's `?` operator is flexible with the `From` trait and crates like `thiserror` provide powerful, idiomatic error composition with detailed context, potentially making it more specific and debuggable than Zig's global error namespace, which some argue discards diagnostic information.

TigerStyle: Performance Philosophy & Practicality

The mention of "TigerStyle" (a performance-oriented design philosophy) in the article initiated a discussion on performance optimization. Some question the practicality of solving performance issues purely in the design phase without profiling, while others argue that deep architectural mistakes are indeed best addressed early. The core idea is about designing with hardware understanding from the start versus iterative profiling.

Zig's Controversial Core Design & Bootstrapping

Beyond allocators, some comments delve into other contentious design choices in Zig, such as its reimplementation of standard libraries (e.g., `libc`, crypto) and how this might impact stability, security, and forward compatibility (especially on platforms like Windows). The bootstrapping process is also debated, with concerns raised about the reliance on binary blobs preventing full source-based builds for distributions. These aspects lead some to question Zig's long-term seriousness or suitability for critical applications.