Zig is a low-level programming language written by Andrew Kelley that focuses on robustness, optimality, and reusability. Most notably the zig compiler is self-hosted. This implies that the zig compiler is written in zig. Zig is a simple language designed without hidden control flow or hidden memory allocations. It also lacks macros and a preprocessor. This guarantees code runs as expected. In terms of speed, Zigs competes with C instead of depending on C.
Zig does not have a garbage collector. Memory allocation in zig is done manually. It is the developer's task to free memory and handle memory errors.
The simplest way to install ZIG
The simplest way to install zig is on Linux is by using
snap , on windows, you can install command line package managers such as
scoop, on mac, you can install zig using
homebrew to install ZIG.
How to Install ZIG on Linux using snap.
How to Install ZIG on Windows.
Option A: Using chocolatey.
Option B: Using Scoop.
Installing ZIG on Mac OS using homebrew.
zig command is not working on your terminal you can locate the zig executable from
bin or wherever it was placed during installation. If you installed ZIG using snap the
zig executable is located in
/snap/bin/zig and can be run directly in the terminal.
If the above guides don't get you set up with ZIG use the below link to install ZIG for your system.
A simple "hello world" in ZIG
Zig files should be saved with an extension of
A simple hello world in zig would look like below:
Some of the zig syntaxes are borrowed from modern commonly used programming languages. i.e.
To simply run ZIG we use the
zig run which usually creates an executable and runs it immediately.
A ZIG "hello world" can also be written as below using functions:
Should you use ZIG in production
I would advise against using ZIG in full-scale production at the moment until the language is fully mature. Things are constantly changing and you might end up with unusable code that spits errors.
Zig advertises itself as a modern C. Its main goal is to compete with C. Zig also allows easy inclusion of C and C++ code in your codebase by shipping with C and C++ compilers. You can even run C and C++ code with ZIG.