A Green Square

What I like about Zig

Published

Zig bills itself as a "general-purpose programming language and toolchain for maintaining robust, optimal and reusable software".

For me, it's a better C without the massive complexity and surface area of Rust.

Read enough posts about Zig, and you'll see patterns emerge:

  • It's quick to pick up and learn.
  • It has safeguards to help you avoid the most common pitfalls of C.
  • Developers seem to become productive with it in a hurry.

Where did it come from?

Andrew Kelley is a developer who was working at OkCupid as a senior backend software engineer and working on Zig during his nights and weekends. OkCupid is interesting because it's actually an open source C/C++ web server disguised as a dating website.

Andrew was maintaining OkCupid's OKWS monolith and slowly migrating it to a service-oriented architecture, but his passion was with his side work on Zig. After giving a talk on Zig in 2018, Zig started gaining popularity. Andrew quit his day job and started living on donations through GitHub's Sponsors feature.

THe Zig Software Foundation was formed to "promote, protect, and advance" Zig as a US-based 501(c)(3) non-profit corporation.

Is it too early?

You might be wondering if it's a good idea to pick up a new language when it's still only at v0.13.0 (as of this writing). Don't be scared.

Andrew Kelley considers v1 to be "the end" of Zig language development. He intends to finish the language and move on. This contrasts with languages like JavaScript where every feature from every other language eventually gets added to it, and the surface area is too large for any single developer to recognize all the features at a glance.

Zig is in production use for some critical use cases.

Who's building with it?

This is a small selection of awesome projects:

  • Bun is an alternative JavaScript runtime with a built-in bundler and test runner, plus a package manager that's compatible with existing Node.js packages. Bun is written in Zig, and it's smoking fast. Along with Deno, it has already had a huge impact on the JavaScript server ecosystem.
  • TigerBeetle is a financial transactions database built for speed, fault tolerance, and mission critical performance.
  • Pluto is an x86 kernel written in Zig that aims to be light and portable.

Check out the Awesome Zig repo for a collection of what's out there now.

What's your favorite feature?

Personally, I like the comptime keyword that forces code to be executed at compilation time. For a great breakdown, check out Loris Cro's blog post What is Zig's Comptime?.

What's the best way to learn?

Start with the Learn page ziglang.org. This links to the best major resources out there.

From that page, I enjoyed the Learning Zig site and the Ziglings project which has tiny broken programs for you to fix while learning the language.