It's another "C but better" language. Contrasted with some of the other solutions in that space, it has an emphasis on stability (once 1.0 is released) and simplicity -- eliminating low hanging fruit in terms of undefined behavior and whatnot, but not significantly hampering expressiveness or requiring excessive syntactic contortions to go the last mile and make it completely safe.
This is actually a surprisingly underserved field. There's relly very few language that actually tries to be just C but better.
Go: Uses garbage collection, not very applicable
Rust: Too complex, more like C++ but better. Bit too cumbersome to write "unsafe" code
D: More like Java/C++, although they have a "better C" mode, but feels like an afterthought
Nim: Uses garbage collection.. like D they're kind of trying to reach down into the plain C usecase, now with some nice reference counting stuff. Also relatively complex
Some actual attemps that I know of: C2, Odin
Some reasons why Zig is a better attempt at "C but better":
- Complexity of the language is just a little higher than C, and mostly in ways that resolves issues with C that leads to its own complexities (Like, the C pre-processor is simple, but solving problems with it can be surpringly complex. Or how you may have to resort to compiler extensions/pragmas to solve real problems)
- The Zig compiler is also a fantastic C compiler
- C headers can be imported and used directly in many cases
- Significant parts of the language is dedicated to excellent interop with C (even has syntax for 0-terminated strings)
- Cross-compilation is a highly prioritized use-case (C is very popular in embedded programming, where cross-compilation is essential)
I don't think it's fair to dismiss some of those, like Rust. That project very explicitly wants to be viable as a safe tool for writing systems code, and the fact that it's accumulated a lot of complexity doesn't take away that intent (or the fact that it's being successfully used in that capacity).
That said, I am super excited about the Zig project, and it hits a sweet spot for me in a way that none of the other "C but better" projects have. Calling it another "C but better" language wasn't an attempt to disparage the project, but to classify it.
> That project very explicitly wants to be viable as a safe tool for writing systems code
Right, but that's a (slightly) different goal from being a C replacement. There are other systems languages besides C, and C is used beyond systems programming.
I guess we're disagreeing about the semantics of "C but better" then. Your position seems to be that a contender would need to be able to replace (and improve) C generally, and I don't totally agree (not that you need to be convinced, but I'll elaborate on my interpretation anyway).
E.g., if somebody came along and said that C would be bloody perfect if it just had a garbage collector then that alternative language would be totally unsuitable as a replacement for C in many contexts, but for a ton of other scenarios it'd still be "C but better," and I don't know that it should be disqualified just because it isn't a full replacement.
Ada is often overlooked. Very short summary: It's like C in that it's plain imperative code that compiles down to efficient machine-code pretty naturally. It's unlike C in that it's much safer, with excellent support for strong optional runtime checks. Ada has excellent interoperability with C. Syntactically it's pretty different from C.
You should try zig. You'll never want to go back, and the c interop is so good, it's easy to kill the c code over time using embrace extend extinguish.
As someone who loves C, Zig has replaced C for me and I don't plan to go back.
There are just too many benefits, not least developer velocity and readability.
Zig is also very approachable to anyone who is familiar with TypeScript, in a way that C isn't. This means more of your team can get excited and get involved, at least in terms of reading the code.
And with Zig, where you have to spend a little extra maintenance time paying for the language being pre 1.0, that's still nothing compared to the upfront and long-lived costs associated with C. You can develop so much faster in Zig compared to C, that you're ahead even pre 1.0.
To expand on this a bit: I feel like learning Zig has helped me better understand C, particularly when it comes to allocation and pointers. Zig has more facilities to specify the intent behind a lot of the common C programming concepts, which has helped make things "click" in both languages.
I’m looking for a new systems programming language. For all the hype of Rust, I don’t think this is it.
How does Zig compare to Nim?
Does Zig have a future in games programming? I feel games programming is the ultimate test, to validate the true success of a programming language.
I do like that Zig compiles to LLVM. Although this in itself will exact a minor performance penalty, in exchange for wider CPU coverage.
Nim transpiles its code down to C, and I’m not certain how that will play out. As you’re now writing your new language on an already somewhat buggy language.
But this does give Nim the possible speed advantage, of getting the code compiled closer to the metal, whereas Zig will compile to the intermedia LLVM layer.
It's going to start compiling to zig IR soon (if it doesn't already), and zig IR will be translated to LLVM IR or fed into zigc. So I think the recommended development cycle will be - use zigc for fast iteration on localdev, then when releasing, use slower LLVM for extra optimization passes and also for cross-compilation.
> gamedev
I think the highest interest in zig is currently gamedev, but there are SO MANY uses for zig.
C doesn't have to die. The point was just that many places where C is currently a good choice you'll find that Zig is also a good choice, and if you like the "but better" features it brings to the table then you'll be inclined to choose Zig. As another comment pointed out, you'll have minimal regret when doing so because the C interop is excellent.
It's a general-purpose programming language, but its primary use case is low-level programming. Anything you'd use C or C++ for today -- OS kernels, command-line applications, games, drivers, embedded software, signal processing, packet filtering, VMs, and applications that require precise control over resources. Zig brings a radical new approach to this niche that reconsiders how low-level programming should be done -- unlike, say, Rust which is an improved C++ -- and is one of the most interesting languages I've seen in a very long time.
Similar to C but less footguns, less error-prone error handling, better meta-programming, really good C interop. If you're writing C (or maybe even C++) on a platform that llvm supports, it's worth checking out.
You have to spawn a thread using a method of your choice. Once you've done thar though zig gives you some very nice async primitives that let you reenter functions and do scheduling/event loops easily, and it's agnostic; the calls autoconvert to blocking if you don't have async. There was a recent demo of task sharing in zig and comparing to go and rust: (https://youtu.be/UaF6-5BmX2I&t=1h10m)
I've even plugged zig into another highly concurrent vm and gotten it to be a "good citizen": https://youtu.be/l848TOmI6LI (these constructs are running concurrently in test and CI so I know they are robust)
I know that as a language author it's natural to assert "it can be used for (almost) everything", but it's not a good strategy for adoption - plenty of languages can claim the same after all.
It's better to mention in which areas it really excels, where it beats the competition hands down.
* Things that would be in scope, but the Zig project is not yet capable of supporting. An example of this would be compiling stuff to GPUs, e.g. SPIR-V. Such things are planned but not implemented. https://github.com/ziglang/zig/issues/2683
* Things that will never be in scope. An example of this would be code obfuscation, which is a use case the Zig project does not recognize.
* Object formats that are drastically incompatible with the von Neumann architecture. It would be infeasible for Zig code to be compiled to such things. For example, attempting to compile to CSS (Cascading Style Sheets).
I think that's it. Anything else would be supported, provided there were enough people interested in providing maintenance for the respective parts of the codebase.
writing code for gpus, writing "code" for FPGAs/ASICs, writing excel macros, writing MAX presentations... Probably most websites (not counting any WASM layers...)
If I like (for whatever reasons) to primarily program in a classical OOP style with objects that have encapsulated state and can be late-bound then at the moment it looks like that this would not be a great use case for Zig. Would this be true?
(BTW I really like Zig's philosophy in general, just saying that this might not be a great use case for it)