Zig

The reason why we can often get away with using languages like Python or JavaScript to drive resource-intensive computations, is because under the hood somebody took years to perfect a C implementation of a key procedure and shared it with the world under a permissive license. - Maintain it With Zig / HN / Home

Zig position itself as better replacement to C.

  • It is a direct (close to system)
  • and simple langage like C, python, Visual Basic, Go…

Introduction to Zig

Zig book

main.zig

const std = @import("std");

pub fn main() void {
    std.debug.print("Hello, Zig!\n", .{});
}

Then to run

  • work from scracth with vscode .runner
  • zig run main.zig - compile & run
  • zig build-exe main.zig - materialize binary
    • ./main - to execute

RAII

Zig does not have RAII in the C++ sense, but it does support deterministic resource management through explicit defer/errdefer and scope-based cleanup - ChatGPT

Object

Zig does not have classes or objects in the traditional OOP sense. - ChatGPT

Zig uses struct to group data and behavior.

  • Methods are just functions with an explicit self parameter (like python)
  • No inheritance (by design)

Zig function

Zig function can return

  • Primitive values
  • Composite types
  • Pointers and references
  • Optional values
  • Error unions
  • Anyerror or specific error sets
  • Types themselves (comptime)

Install

As of now, Zig is generally not included in the official Debian repos. The easiest way seems to use Hombrew or Nix (prefered for linux)

Nix Install

Using nix profile

$ nix profile add nixpkgs#zig

C++ interop

Zig Interop Overhead Table with Metrics

These are rough per-function call latencies on modern desktop CPUs. Actual values vary based on OS, CPU, type conversion, and data size.

Language Interop Method Typical Workflow Overhead Level Approx. Call Latency*
Java JNI Zig shared lib loaded via System.loadLibrary() Low ~50–200 ns per native call
  JNA/JNR Reflection-based FFI Medium ~1–5 µs per call
  IPC (sockets, REST) Zig as separate process High ~100 µs – 1 ms per request
C++ C ABI wrappers extern "C" Low ~5–50 ns per call
  Direct C++ interop @cImport + C++ Medium ~50–200 ns (depends on ABI, exceptions)
Ruby C extension Zig lib loaded as native Ruby extension Low ~50–200 ns per call
  Ruby FFI (ffi gem) Zig C ABI lib via FFI Medium ~1–5 µs per call
Python CPython C API Zig compiled as Python module Low ~50–200 ns per call
  ctypes/cffi Zig C ABI lib loaded in Python Medium ~1–10 µs per call
General IPC Sockets/pipes/gRPC High ~100 µs – 1+ ms per round-trip

see also

Written on October 18, 2021, Last update on December 14, 2025
lang zig golang c++ rust