3 ms·
> taking it for what it was – a modern “C+” alternative Andrew Kelley, Zig's designer, presents Zig as an alternative to C because it can replace C where it is
by pron 5y ago
> taking it for what it was – a modern “C+” alternative
Andrew Kelley, Zig's designer, presents Zig as an alternative to C because it can replace C where it is used, but even though C served as a conceptual starting point in the language's design process, comparing the language itself to C (or "C+"), as opposed to C++, doesn't quite capture the language's design and feel.
Superficially, what makes Zig feel "slim" compared to C++ is that 1. it disallows any kind of name overloading (and, so, in particular operator overloading) -- any (namespaced) name in a Zig program can refer to only one definition -- and 2. it is a very simple language that can be fully picked up in a day or two by anyone with experience in any low-level language (C, C++, Rust, or Ada). But Zig is both safer and more expressive than C++; any "rich" C++ construct that makes clever use of, say, templates, can be expressed in Zig and more easily, thanks to Zig's comptime and introspection, and much more. It is no coincidence that programs are short in comparison to other low-level languages. It's not that the language is terse, but that its simple constructs are powerful, similar to how Lisps can be simple yet expressive, although Zig's comptime + introspection replaces Lisp's macros as the "power feature" (and comptime + introspection is easier to read and write than macros). So while the language shares some basic primitives with all low-level languages, like precise control over data representation, it doesn't feel like any other language.
I see Zig as an entirely new, and quite revolutionary approach to low-level programming, that doesn't follow any design tradition in that space, neither C's sparseness nor C++/Ada/Rust's linguistic richness. It is something new altogether.
Different languages appeal to different people based on their aesthetic preferences and priorities (e.g. C++ and Rust prioritise the code appearing as if written in a high-level language when read on the page, while Zig prioritises explicitness and compilation times), and surely some developers would prefer C++ or Rust to Zig, just as surely as others would prefer Zig, but to understand what Zig is, it has to be experienced, because it really is hard to compare to anything else. Thankfully, being so simple and easy to learn, experiencing it requires very little investment. You may find it a promising prospect for any low-level programming task, regardless of whether it would have otherwise suited C or C++. It can replace C++ just as much as C, and even C++ developers would find it compares very favourably when it comes to expressive power.