Four Months of Zig

68 points by Defelo


zmitchell

This contrasts to Rust, which leads programmers to insert panics into their code.

Inserting panics is definitely not the norm.

In Rust you can use ?, which is quicker than unwrap, but you also have to do something like Result<Type, Box<dyn std::error::Error>. That's a mouthful! Alternatively, you can use the anyhow crate and return anyhow::Result, which also provides some nice helper methods. But then you have to add a dependency for reasonable error handling. There's also Zig-style composable errors with yet another library.

You definitely don't have to return a boxed error. In fact I consider that a code smell. The alternative not discussed here is to define your error enum like you would with thiserror and then implement the Error trait yourself. This is totally doable, and not that much of a pain if you're wanting to avoid a dependency.

Nitpicks aside, one of the things I struggle with in Zig sometimes is that starting a new project can be a worst case scenario for an ADHD brain. When I'm starting a new project I want to jump right in to tinkering on the problem, and instead I find myself wiring up similar functionality in build.zig that I use in many projects (check step to help out ZLS, test steps, etc). By the time I'm satisfied with my build.zig I've already spent a chunk of my dopamine budget on working through a part of the project I find aggressively uninteresting 😅

Anyway, @liberty definitely come say hi in Portland :)