In this week’s newsletter, we’ll be taking a look at the Zig programming language.
Zig is a general-purpose programming language and toolchain designed for maintaining robust, optimal, and reusable software. As a project that started in 2015, Zig aims to combine the strengths of languages like C, C++, Rust, and Go while offering enhanced developer experiences and comparable performance (1).
Key features of Zig include:
Zig positions itself as a potential successor to the C programming language, offering a safer, less buggy, and more maintainable alternative for systems-oriented development.
The language emphasizes simplicity and ease of use, with a small feature footprint and a commitment to providing a single obvious way of doing things. This design philosophy aims to make Zig easier to learn and apply compared to more complex languages like C++ or Rust.
Zig has been gaining significant traction recently with a 50% growth in developer interest according to one recent language rankings report (2).
Here, we see the rate of increate in Zig’s GitHub star history:
(3)
Zig is being used in various areas, such as game development, WebAssembly, systems programming and various open source projects.
mkdir hello
cd hello
zig init
hello
directory using VSCode. Install VSCode’s “Zig” extension for syntax highlighting and more.src/main.zig
with:const std = @import("std");
pub fn main() !void {
const start_value: u128 = 5;
const num_to_print: usize = 10; // Number of Fibonacci numbers to print
var a: u128 = 0;
var b: u128 = 1;
// Find the first Fibonacci number >= start_value
while (b < start_value) {
const temp = a + b;
a = b;
b = temp;
}
std.debug.print("Fibonacci sequence starting from {d}:\n", .{b});
var i: usize = 0;
while (i < num_to_print) : (i += 1) {
std.debug.print("{d} ", .{b});
const temp = a + b;
a = b;
b = temp;
}
std.debug.print("\n", .{});
}
zig build run
As you can see the syntax is very simple.
My quick take:
Zig feels a lot like Go in a way, regarding its simple syntax. This is refreshing coming from the complexity (and sometimes too much magic of Rust's macro system).
It's refreshing to have the ability to manage your own memory vs say, the strictness of Rust's borrow checker. It kind of reminds about my Objective-C days which I enjoyed working with.
If I need to integrate with C libs, it's a huge win, as there is no need for FFI layers.
My latest favorite cross-platform terminal application, Ghostty, written by the founder of HashiCorp, is written in Zig (4) to ensure fast performance (Zig compiles to native machine code), cross-platform compatibility, low level control with the ability to have fine grained control over memory management and an approachable, fun syntax and language design.
I think if I was writing something that needed high performance, especially if it needed seamless interop with C libraries (without needing an FFI layer), I would strongly consider Zig over say, Rust. As to why, that’s probably a topic for another blog post.
What Do You Think? Are you interested in more Zig tutorials? Reach out at hello@seenickcode.com
As always, happy coding,
Nick