I rewrote my Rust keyboard firmware in Zig: consistency, mastery, and fun

I’ve spent the last year building keyboards, which has included writing firmware for a variety custom circuit boards.

I initially wrote this firmware in Rust, but despite years of experience with that language I still struggled quite a bit. I eventually got my keyboards working, but it took an embarrassingly long time and wasn’t fun.

After repeated suggestions from my much more Rust-and-computing-experienced friend Jamie Brandon, I rewrote the firmware in Zig, which turned out swimmingly.

I found this quite surprising, given that I’d never seen Zig before and it’s a pre-1.0 language written by a fellow PDX hipster with basically just a single page of documentation.

The experience went so well, in fact, that I now feel just as likely to turn to Zig (a language I’ve used for a dozen hours) as to Rust (which I’ve used for at least a thousand hours).

This, of course, reflects as much about me and my interests as it does about either of these languages. So I’ll have to explain what I want from a systems programming language in the first place…

https://kevinlynagh.com/rust-zig/

This thread was posted by one of our members via one of our news source trackers.

Corresponding tweet for this thread:

Share link for this tweet.

This was an excellent article and I enjoyed reading it several days ago.

However, you can tell right from the start that the author initially picked Rust based on hype alone and didn’t do proper pros/cons analysis. He felt happy with his choice of Zig because it was much better positioned to comply with his requirements for lower-level code that doesn’t tackle memory safety concerns and object lifetimes.

All in all, he eventually made the right choice but in the HN thread some people went as far as to claim that Rust is “bad” which of course it is if you pick it for the work that the author wanted; the Rust book is literally warning against some of his requirements in its intro pages!

So the article is valuable but it attracted some rather preliminary and harsh responses.

3 Likes

I saw the article on HN and I think you are right there were some exaggerations in the comments, no language is good or bad - a programming language is a tool. The article make me curious about Zig, so now I have to find a small project to play with the language.