Zig is a nice language, but those articles always compare new languages against old-style C without use of modern tools. Most of the listed advantages you can have in C as well if you are willing to adopt modern tooling and style: signed overflow checking: sanitizers, errors you can not ignore: [[nodiscard]], slice type which know their size: variably-modified types or span types.
Defer will also appear in C compilers soon, but personally I still think goto-error handling is clearer.
(Rust has an advantage for temporal memory safety, but this does apply to Zig.)
It seems that part of what Zig is trying to do, though, is create a pit of success around these practices. So the response might be something like, “Yes you can do these things in modern C, but doing it consistently requires more discipline than we’d like.”
IMO you cannot fairly compare static analyzers/sanitizers with features baked into the language/compiler.
Though I've noticed the same trend when reading a famous Rust primer for C++ developers. Like there are obviously so many good and valid arguments when comparing the two languages that would've gotten the point across. Yet the authors felt the need to push it one step further, where the comparison no longer seems fair. Like comparing Rust with C++17 when C++20 provides the same exact feature that Rust claims to provide.
I'm very certain you can statically analyze zig's IR for safety without language change. And zig makes it easier to get consistency than C because you are steered away from the mishmash of malloc/jemalloc/pick-your-allocator-function. (The analyzer can say "all bets are off if you don't use the allocator interface") same with the new stdlib io interface for async-shaped analysis on aliasing analysis
Zig's tooling is very good, so is the cross-compatibility story and tagged unions.
But while you can have some/most of the benefits Zig has from modern C, I think an underrated benefit is the language culture. As a different language it was the opportunity for a reset, e.g. it's idiomatic Zig to pass allocators to functions, meaning every library in Zig will work this way.
You could do that in C, but none or very few libraries do that so whenever you reach out to third-party dependencies (which is not a lot, in C as in Zig) you have to fight against C's traditional patterns.
People say the same about Rust, and seems tooling for you all mean "convenient cli program" and not "vast IDE support, debuggers, qualified and platforms-specific toolchains, formal verification software".
In those C blows Zig, even Rust, out of the water.
As soon as you have dependencies you are dealing with however the authors decided to build things.
Part of why languages exist is just to get a new ecosystem.
At this point, you could fork C/C++, only remove features, give it a new name, a new package service, and maybe fork the standard library, and you could end up with something pretty competitive against Zig or Rust.
But Zig is expressly not trying to bootstrap a completely new ecosystem. Integrating with - and depending on - existing C and C++ code is a core use case. So much so that they’ve adopted “maintain it with Zig” as a motto that intentionally puns on “rewrite it in Rust”.
I don't see why this requires not having dependencies.
Yes, new languages try to create a new ecosystem. I think this is a bad thing - we already have too many of such - often somewhat isolated - language ecosystems. But I also do not think we need new ecosystems, when we can evolve the existing one. I have seen C evolve quite a bit over time, so the idea that we have to create new ecosystems to solve problems is wrong in my opinion. C evolves very slowly, which means that some things need more time, but I also think that it is generally a very good thing that it evolves slowly.
Because some of those tools exist since 1979, and it keeps being a quixotic battle to make corporations adopt them as standard, until cybersecurity legislation started to take off.
I think this is indeed the main problem. But it would also be the proper solution. For some the "in C/C++ this can not be fixed" narrative is a convenient excuse not to improve their code. Those parties will also not rewrite in Rust, because even with AI this more effort than zero, and zero effort is what they aim for. (and some of those parties are represented in standardization committees and vote against stricter requirements)
I’ve settled on a dialect of C++ for systems programming after using C for a long time. It’s mostly C-like and I disable exceptions, RTTI, etc. but I do use templates, overloads, methods, lambdas, etc.
I have my own object system with constructor methods that all return a status code so you don’t need exceptions, my own stdlib for containers, buffered I/O, networking, hashing, math, threading, async, etc.
C++ gives you all the features to effectively build your own language, and you can use first class tooling since C++ is widely supported. LLMs also make it much easier to build out and test an entire stdlib on your own.
This is why we need natural language -> pseudo code -> GC typed -> Low level systems.
Both Zig and Rust are fine as the last stage of this software development pipeline with different trade-offs. Problems arise when people try to use them earlier in the process.
What many miss is that having a GC, regardless of the implementation algorithm, doesn't preclude low level coding abilities, e.g. D, Swift, C#, Nim, Go,...
I've essentially done much the same. One of the more under-rated features of C++ is being able to build a new language environment based on a different set of composable idioms from the low-level primitives on up.
C++ is as much a tool for building nice systems DSLs as it is a systems language. The heavy investment in compile-time expressiveness has really paid off for the language over time.
I don't write much C or C++, but I like writing transpilers and got pretty far with an F# to C backend a while ago, and it was pretty difficult for me (granted it was my first codegen project)
I tried it again with C++ out of curiosity and C++ is ridiculously featured for making it into your own and little domain languages or something that feels like a new feature. Genuinely kind of awesome for transpilers and it definitely gave some insight to the "C++ is awesome, but you have to pick the 20% of features you like" wisdom I've heard
LLMs were fun for exploring C++ patterns as well. I could ask it techniques for approximating some construct in another language and get a full page of toys to try out. It definitely made me want to explore templates in my own language in addition to runtime generics
Agreed. I'd not ditch the STL completely, but only use its freestanding subset. Implementations contain some very fast SIMD-accelerated code[1]. +The STL works without exceptions.
Also, Zig is as at least as expressive as C++ (but without the implicitness and general language complexity that makes reviewing some sensitive code, where you need to see exactly what operations are performed, hard), and it supports arenas better than C/C++/Rust.
Seems like a long way to walk though. Retrofitting this will take time (if it'll ever complete).
Zig made it a core part of the language and library. I'll assume Rust will make it farther than C++ ever made it, but just take a look at how retrofitting custom allocators is going there.
Seems like it will be useful for use-cases like embedded where you're restricted to certain parts of the library anyway. But the battle is kind of already lost for support at the level of Zig or Odin. Even if they retrofitted support for the whole standard library, they'll never be able retrofit all crates or make people even bother adding support for all new crates.
In critical low-level code, any kind of overloading - operator or otherwise - is something you'd rather not have.
By expressivity I don't mean what characters you use in the conrecte syntax, but the number of lines needed to express an algorithm (up to a small constant). C doesn't have C++'s expressivity because it lacks templates, and while you can sort of express that kind of thing with macros, it's not all the way there. Zig, however, gets you all the way there (you might need to write matrix_plus instead of +, but the expressivity is the same).
Many people are against operator overloading, imo my only issue with C++ operator overloading is that you're allowed to overload the the assignment operator. From what I can see this is the root of many issues
Is there a way to support varying the meaning of "+" etc without introducing a lot of complexity? I suppose if Zig had nested functions, and the ability to define a nested function called "+", then you could have name shadowing instead of "overloading".
OCaml basically gives you operator overloading this way without actually doing overloading. I'm wondering why we can't have these OCaml-isms in other languages - without needing to use OCaml - which sadly comes with other commitments.
Regarding the threads I'm seeing in the comments here: it's so frustrating that we have languages like Zig and Nim, among others, which are built for beauty and intuition, but then we have the naysayers that just say "everything that's not Rust or Go is dead because of LLMs, it's over, shut it down and go home".
The ability to vomit out half-baked fragile code at record speeds via plagiarism factories of unprecedented scale with little mental overhead has swung the pendulum so hard in the opposite direction of intellectualism and the human mind. This is why people are depressed about AI. It's a revolution toward soullessness.
struct user *user_new(const char *name, size_t n_groups)
{
struct user *u = malloc(sizeof *u);
if (u == NULL)
goto fail;
u->name = strdup(name);
if (u->name == NULL)
goto fail_user;
u->groups = calloc(n_groups, sizeof *u->groups);
if (u->groups == NULL)
goto fail_name;
return u;
fail_name:
free(u->name);
fail_user:
free(u);
fail:
return NULL;
}
I think you can represent C better than this. I like to focus on one cleanup block, and exploit the fact that free(NULL) is a no-op.
struct user *user_new(const char *name, size_t n_groups)
{
struct user *u = calloc(sizeof *u, 1);
if (u == NULL)
goto fail;
u->name = strdup(name);
if (u->name == NULL)
goto fail;
u->groups = calloc(n_groups, sizeof *u->groups);
if (u->groups == NULL)
goto fail;
return u;
fail:
if (u)
{
free(u->name);
free(u->groups);
}
free(u);
return NULL;
}
Although note that this assumes calloc(sizeof *u, 1) initializes pointers to NULL, IIRC assuming the bit pattern of NULL is all zeroes is technically against the standard but every system you're likely to target will still work.
If you follow the pattern of "it's OK to free NULL pointers", you can also re-use a free function:
struct user *user_new(const char *name, size_t n_groups)
{
struct user *u = calloc(sizeof *u, 1);
if (u == NULL)
goto fail;
u->name = strdup(name);
if (u->name == NULL)
goto fail;
u->groups = calloc(n_groups, sizeof *u->groups);
if (u->groups == NULL)
goto fail;
return u;
fail:
user_free(u);
return NULL;
}
void user_free(struct user *u)
{
if (u)
{
free(u->name);
free(u->groups);
}
free(u);
}
Then user_free() can also be a user-facing API function for cleanup, used elsewhere, and it can be written to be cool with tearing down partially initialized structures.
All these new languages are unreadable relative to C. If, like me, you like explicit stuff like for (size_t i = 0; i <= n; i++) total += a[i]; all these new languages won't do it.
I don't like this explicitness, because very often it's a lie. In the times of PDP-11 that would compile into a literal counter and literal ADD, DEC, and BNE instructions. Now it will most often compile into some vectorized semi-unrolled form with seven-letter instructions like VPHADDD which add many integers at once, etc.
If I want specific instructions to be run in a specific order, like touching hardware registers, I reach for intrinsics or assembly. If I want an array summed, I prefer to express the intent: total = the_array.sum(); I leave the implementation to the compiler / stdlib.
Funnily, Zig does allow doing it explicitly like that, just need use while rather for:
var i: usize = 0;
while (i <= n) : (i += 1) {
total += a[i];
}
That said, perhaps Odin, for which simplicity and readability is guiding principle in its design, is more up your alley. In Odin, can be read:
for i := 0; i <= n; i += 1 {
total += a[i]
}
Exactly same style can be used in Go & V (which is/was? quite infamous here in HN). But in all languages, for this example at least, a foreach-like iteration, i.e.
C is in some ways minimal, but the pointer-syntax and some more I absolutely dislike. I also found C++ easier to use in some areas, such as:
cout << "Hey there" << endl;
The equivalent C is simply uglier. Of course C++ failed in other areas big time, but for such simple things like above, I think C++ is better than C. Naturally that cout example is very simplistic, but one can find other examples where C is really quite ugly.
puts("Hey there"); is worse than C++ iostream? In my opinion, even printf style strings are better than iostream shenanigans. The main downside of printf is addressed in more modern languages like rust which allow the printed parameters to be embedded in the string so you don't have to keep track of the ordering.
I honestly don't think total = a.sum() is any less explicit than for (size_t i = 0; i <= n; i++) total += a[i]. If anything, a.sum() is more explicit as at least it expresses the programmer's intention explicitly. The loop is one more layer between the reader and the writer's intention, without faithfully reflecting what happens on the bare metal. So it's the worst of both worlds.
A toy example is meant to demonstrate a principle. Toy examples often have alternative ways they can be written, but the concept they are meant to demonstrate requires the whole machinery being employed. Furthermore, how do you think .sum is implemented?
It's not very readable. The logic is forced to always use often useless counters and check them, even on the syntax level. I will take any for each mechanism over the loop style. Map, reduce, fold, all better than having to write counters and the check for it.
Rust will take over all these niche languages anyway. Yes, Rust is a viable replacement for C and C++ in the long term. Zig is just trying to be a middle ground, which we've established doesn't work. Zig is particularly irrelevant compared to Rust in the LLM era.
I can tell you've never written any low level stuff in Rust. When you get to the absolute lowest level of programming, there are tings the compiler cannot prove. Which makes you use unsafe Rust, but that doesn't turn off the Rust compiler rules, so you are forced into this awkward way of programming just to side step the compiler rules. Graphs, linked lists and caches are so painful to write in Rust.
That's overly confident. When I see Rust code, I'm immediately reminded of Scala and how it was supposed to take over the JVM world, but did not, and Kotlin, a much simpler language, is getting more and more popular. You might claim that LLMs have no problem with that kind of language complexity, but people still need to review stuff. I have no doubt that Rust will reach C++ level of popularity, but that still leaves a lot of space for other low-level languages.
Scala "failed" for two reasons: Firstly, (like Haskell) it quickly exceeded its weirdness budget, and cultivated a community that embraced and sustained that weirdness. Secondly, a number of prominent individuals publicly expressed political views that made it hard for engineers in "mainstream" organisations to loudly promote Scala.
I think Rust is doing much better on both fronts. It has always been a more pragmatic language than Scala, and the way it is developed supports that, rather than pushing the weirdness budget higher. The overall political lean of the Rust community is also more amenable to support in mainstream institutions + companies.
Those advocating for the take over always forget, every single time, that they are a guest language, those developing the underlying platform have zero interest into taking their desires into account.
These even applies to C++, born on UNIX out of C, and regardless of rants, it is 100% obvious to me that there wasn't a single UNIX platform that would care to use C++ instead of C on its core implementation.
> Zig is particularly irrelevant compared to Rust in the LLM era.
This. If we continue on this LLM/AI trajectory, and you're not constrained by your platform to use a specific language, why would you choose C or Zig or C++ over Rust?
You won't be reading or writing the code yourself, LLMs will, and they benefit from a strong type system that catches a lot of issues, meaning fewer tests are needed.
Not really, Zig takes the exact opposite stance as Rust for correctness.
Rust is the language defending itself against human mistakes whereas Zig promises the dev/agent total freedom by eliminating implicit interactions. That makes zig more readable/approachable without needing large amounts of context.
If they can get the tooling situation handled better with 3.0, Nim will be probably the best all-around programming language in my book. The only reason I tend to opt for Zig instead (and the reason the library ecosystem is pretty small) is that it just feels a little unpolished all over the place. But the core principles are just so good.
I don't mean that as an insult to Zig. Zig is amazing. But the ergonomics of Nim are just unbeatable.
God I loved playing around with D back in the day when I was in high school. It seemed like a no-brainer that it was going to be huge. It's such a shame it never took off. Incredible language.
It's so damn nice, its a shame it's never taken off the way it could. I think there's still time to make it attractive to companies, but with people's increasing use of AI I don't think anyone even cares what language their model writes in, look at the insane uptick in Rust programming.
It’s pretty obvious why they didn’t, they’re GC by default. That’s already enough to put people off, even if it’s “not a problem” in reality, people will just avoid it for systems programming if they hear that, they will assume all the good features need the GC
Nim is stack allocated by default, and you annotate types explicitly with `ref` to use the GC. Even then, the compiler elides reference counting using borrow checks, you can choose different GC options, and the GC isn't stop the world like most. You don't need to touch reference counting if you don't want to, and Nim fits embedded dev pretty well for that reason.
I like both of those, I like the idea of Zig, it does seem to be striving to be pure in some areas where C is "king" that other languages gloss over, but Zig is always changing, and its got some elitist people in its ranks that left me not wanting to bother with it. Imagine a programming language maintained and used by geohot clones.
It's okay for me to declare a macro with `__attribute__((warn_unused_result))` for GCC and Clang, and `[[nodiscard]]` when the C code is later compiled with C++ (or nothing).
I've been toying with the idea of learning zig and weirdly enough I was looking at this guys book. I don't have any experience with low level languages. The closest I've gotten is Go.
I was debating between C and Zig, but I still don't really know what I want to choose. Feels like C is probably the right choice given the languages age and it could technically be more useful (not that I'd be looking for a job doing C work).
C is still supreme for working on the majority for a Linux/BSD system stack. It also imparts skill that transcend to most other spaces where you may eventually need an FFI to interact with a library anyway or understand how it actually runs on a system.
It depends for what you want it. If you're going to do an API, well, Golang is more practical here in my opinion. For TUI apps, I would dare to say Rust was more pleasant than Golang. My experience with Zig was limited, I would not say is not a good fit.
I would say from a pedagogical perspective, learning C is hugely useful for understanding how programming works at a much lower level.
This has the benefit of you learning about manual memory management and how to deal with all the issues that come with such a rules free language like C that will basically let you do anything. This understanding means lot of the constraints and features that safer languages like Zig and Rust add start to make a lot more sense. For example, going from Python to Rust, the borrow checker will probably seem rather arbitrary, but going from C to Rust, you will find the borrow checker is just automating a lot of checks you were already doing yourself.
For that matter, assembly is useful as well. Not that you have to become an expert in it, but do enough that you understand it from a practical standpoint. It doesn't even have to be on x86, use an emulator of something simple like a 6809 or 6502. I never had trouble understanding pointers in C once I had some experience writing assembly code.
I think you should know C if you want to do low level stuff. It will help understand why zig (or rust) is built the way it is and what is useful about it, too.
I don’t get it, C arrays can be used as slices, no?? Given a pointer and a length, which is how C does any array, works just as well (I mean if you consider arrays without a length a fine thing) as a slice!
C is far behind the sate-of-art in C and Go families. True, but not bad.
It is what it is, but can work on what it already has, while keeping its tradition.
Small changes, add common extensions, conservative additions, improve coherence and correctness of the standard while keeping easy to implement and small.
No crazy things.
Keep in mind that it is standardized and targets things others do not target.
AI slop. Every article on this site has "The honest tradeoff" as a header. Looks like it was generated to promote a book which is no doubt also just slop.
Up until about a week ago, I had no sympathy for people complaining about "AI writing style" in articles - and then all of a sudden it hit me. Kind of like unexpectedly developing an allergy to sawdust.
> Every article on this site has "The honest tradeoff" as a header.
This is a hallucination. I'm sorry. This is what we call these kind of statements these days. Unless you can prove your humanhood, that's how it is now.
I wrote recently about a weird issue I encountered with Zig, though to be fair it was related to using Zig to compile C code, humorously in a Rust project (which touches on all of the languages mentioned in this post).
While I did just dismiss it as an edge issue, it turns out that this same rather clumsy sort of mistake has happened repeatedly in Zig's pure rewrite of MUSL. And despite being an absolutely catastrophically bad problem, by my judgment, the problem is still in main at this moment, across a wide number of musl function rewrites.
Which gives me pause about the whole zig project. If you're rewriting a critical library, making such simple but consequential mistakes shouldn't happen, and if they do happen it should be a red alert type situation.
When working with Zig, you are a beta tester. The development process is unfortunately not great, so bugs slip in fairly easily. You need to be ready for it and test your application properly. Large Zig projects don't target the latest version. That said, if you can deal with that, you get a great language that is fun to use and very practical. I think it's worth it, even if it can be frustrating at times.
Personally I think it's not that catastrophic for zig < 1.0. Just a performance regression, and one can always link to other libc implementations, or is their own implementation enforced now?
If errors like this are acceptable because of the version number of an otherwise decade old project, then that's ample evidence of why Zig is not ready and should not be used for any software that needs surety.
Zig can be a hobby/learning project (in which case these elementary mistakes, and the lax development process that allowed them, are totally acceptable), or it can be a project that targets critical applications (like TigerBeetle, which handles REAL MONEY), but it can't be both.
It isn't my thing though. It's quite literally, by choice, their thing. They are the ones who decided that rewriting musl in zig was something they need to do and was such a priority. Only it's a serious regression.
But I mean, the six people in a trenchcoat comment is basically precisely what should give people pause. In my project I simply eliminated zig from the stack entirely because even if I worked around the problems, what comes next? What's the next showstopper that gets waved away as oh well six people in a trenchcoat...
"C is not going away and I still read a lot of it, because the UNIX source code and most system libraries are written in C and their man pages document them with C prototypes. But for new code I choose Zig."
Has this aged well though?
The TechBros pour in tons of money into "agentic programming" or "agentic workflows" right now. You can see that all over the place; OmarchySlop and other AI-controlled projects, where Claude is now the main designer. So in such a scenario, where does Zig really fit in? The "but for new code I choose Zig" is not a really compelling argument IMO. It reminds me of the issues that D has ("we are the better C++!!!" or even Java too). It's interesting that so many languages try to replace C. All failed, IMO. And C is still a pretty bad language. For instance, I think almost everyone would concede that crates in Rust are useful or good; C++ kind of submitted to this and has their own variant now as far as I know. C does not - or perhaps it has but almost nobody would know it.
I kind of want a language that really sits like in both camps: compiled, and scripting use. But each language seems to just fail hard in one area. Including syntax-wise. Complexity-wise too; I find Rust annoyingly complicated. Go is in many ways simpler than Rust, but it sucks in other ways. Of course there are always trade-offs either way, but I kind of want a language that can offer insane speed while having a great syntax (crystal also fails here; it is fast but the syntax is pretty bad. Why is "alias xyz abc" not working? It's so easy to support. But anyway I could go on for years here.)
My goto language for both fast and still scriptable is Dart. They invested a lot in UX and performance in the last few years and it shows. Run as a script or compile to a small binary that runs pretty fast, similar to Go performance as as as I have bothered to check. Best DX out there even if you don’t care about Flutter.
Their rewrites of all security critical libraries while also refusing to use AI which at the moment is surfacing huge vulnerabilities all over the place.
Zig is a nice language, but those articles always compare new languages against old-style C without use of modern tools. Most of the listed advantages you can have in C as well if you are willing to adopt modern tooling and style: signed overflow checking: sanitizers, errors you can not ignore: [[nodiscard]], slice type which know their size: variably-modified types or span types.
Defer will also appear in C compilers soon, but personally I still think goto-error handling is clearer.
(Rust has an advantage for temporal memory safety, but this does apply to Zig.)
It seems that part of what Zig is trying to do, though, is create a pit of success around these practices. So the response might be something like, “Yes you can do these things in modern C, but doing it consistently requires more discipline than we’d like.”
https://blog.codinghorror.com/falling-into-the-pit-of-succes...
I do not think it needs a lot of discipline. It needs the willingness to do it, but this is also true for adopting a different language.
Most of those practices were already available out of the box in languages like Object Pascal and Modula-2, or languages that predated C for a decade.
C authors created lint for similar reasons.
It has always been a social problem, getting some class of developers to actually care.
might as well use rust and fall into a much wider and deeper pit of success
IMO you cannot fairly compare static analyzers/sanitizers with features baked into the language/compiler.
Though I've noticed the same trend when reading a famous Rust primer for C++ developers. Like there are obviously so many good and valid arguments when comparing the two languages that would've gotten the point across. Yet the authors felt the need to push it one step further, where the comparison no longer seems fair. Like comparing Rust with C++17 when C++20 provides the same exact feature that Rust claims to provide.
I'm very certain you can statically analyze zig's IR for safety without language change. And zig makes it easier to get consistency than C because you are steered away from the mishmash of malloc/jemalloc/pick-your-allocator-function. (The analyzer can say "all bets are off if you don't use the allocator interface") same with the new stdlib io interface for async-shaped analysis on aliasing analysis
github.com/ityonemo/clr
Where do you think the static analyzers are baked into for C?
Zig's tooling is very good, so is the cross-compatibility story and tagged unions.
But while you can have some/most of the benefits Zig has from modern C, I think an underrated benefit is the language culture. As a different language it was the opportunity for a reset, e.g. it's idiomatic Zig to pass allocators to functions, meaning every library in Zig will work this way.
You could do that in C, but none or very few libraries do that so whenever you reach out to third-party dependencies (which is not a lot, in C as in Zig) you have to fight against C's traditional patterns.
> Zig tooling is very good
People say the same about Rust, and seems tooling for you all mean "convenient cli program" and not "vast IDE support, debuggers, qualified and platforms-specific toolchains, formal verification software".
In those C blows Zig, even Rust, out of the water.
That works as long as you have zero dependencies.
As soon as you have dependencies you are dealing with however the authors decided to build things.
Part of why languages exist is just to get a new ecosystem.
At this point, you could fork C/C++, only remove features, give it a new name, a new package service, and maybe fork the standard library, and you could end up with something pretty competitive against Zig or Rust.
But Zig is expressly not trying to bootstrap a completely new ecosystem. Integrating with - and depending on - existing C and C++ code is a core use case. So much so that they’ve adopted “maintain it with Zig” as a motto that intentionally puns on “rewrite it in Rust”.
I don't see why this requires not having dependencies.
Yes, new languages try to create a new ecosystem. I think this is a bad thing - we already have too many of such - often somewhat isolated - language ecosystems. But I also do not think we need new ecosystems, when we can evolve the existing one. I have seen C evolve quite a bit over time, so the idea that we have to create new ecosystems to solve problems is wrong in my opinion. C evolves very slowly, which means that some things need more time, but I also think that it is generally a very good thing that it evolves slowly.
comptime instead of preprocessor macros is pretty big though…
I mostly agree, but as usual there are the classical catches:
1. yeah you can do that, but we should really do some (most? all?) of the things you mention (as well as other safeguards) mandatory
2. your code might be alright, but what about your dependencies ?
Because some of those tools exist since 1979, and it keeps being a quixotic battle to make corporations adopt them as standard, until cybersecurity legislation started to take off.
I think this is indeed the main problem. But it would also be the proper solution. For some the "in C/C++ this can not be fixed" narrative is a convenient excuse not to improve their code. Those parties will also not rewrite in Rust, because even with AI this more effort than zero, and zero effort is what they aim for. (and some of those parties are represented in standardization committees and vote against stricter requirements)
Of course C can do anything that Zig can, but Zig (and Rust) can reject bad C code by design.
It is guaranteed that you cannot write non-modern C code, that's why ppl are using new languages.
There's a big difference between opt-in and opt-out features.
I’ve settled on a dialect of C++ for systems programming after using C for a long time. It’s mostly C-like and I disable exceptions, RTTI, etc. but I do use templates, overloads, methods, lambdas, etc.
I have my own object system with constructor methods that all return a status code so you don’t need exceptions, my own stdlib for containers, buffered I/O, networking, hashing, math, threading, async, etc.
C++ gives you all the features to effectively build your own language, and you can use first class tooling since C++ is widely supported. LLMs also make it much easier to build out and test an entire stdlib on your own.
The reason why I prefer a GC based compiled language with types vs Rust or Zig is that they put memory allocation front end center in the language.
Sometimes I want to think about algorithms and memory management separately.
Try translating to zig.This is why we need natural language -> pseudo code -> GC typed -> Low level systems.
Both Zig and Rust are fine as the last stage of this software development pipeline with different trade-offs. Problems arise when people try to use them earlier in the process.
Same here, as per my comment history.
What many miss is that having a GC, regardless of the implementation algorithm, doesn't preclude low level coding abilities, e.g. D, Swift, C#, Nim, Go,...
> Try translating to zig.
No problem:
I've essentially done much the same. One of the more under-rated features of C++ is being able to build a new language environment based on a different set of composable idioms from the low-level primitives on up.
C++ is as much a tool for building nice systems DSLs as it is a systems language. The heavy investment in compile-time expressiveness has really paid off for the language over time.
I don't write much C or C++, but I like writing transpilers and got pretty far with an F# to C backend a while ago, and it was pretty difficult for me (granted it was my first codegen project)
I tried it again with C++ out of curiosity and C++ is ridiculously featured for making it into your own and little domain languages or something that feels like a new feature. Genuinely kind of awesome for transpilers and it definitely gave some insight to the "C++ is awesome, but you have to pick the 20% of features you like" wisdom I've heard
LLMs were fun for exploring C++ patterns as well. I could ask it techniques for approximating some construct in another language and get a full page of toys to try out. It definitely made me want to explore templates in my own language in addition to runtime generics
Agreed. I'd not ditch the STL completely, but only use its freestanding subset. Implementations contain some very fast SIMD-accelerated code[1]. +The STL works without exceptions.
[1]: https://github.com/microsoft/STL/blob/main/stl/src/vector_al...
This is the way, take what suits your use case, using C++ doesn't mean taking the whole feature list.
And don't work with anybody who has a different favorite subset of C++!
What are you using for a build system?
Also, Zig is as at least as expressive as C++ (but without the implicitness and general language complexity that makes reviewing some sensitive code, where you need to see exactly what operations are performed, hard), and it supports arenas better than C/C++/Rust.
To anyone interested in arena allocators.
Rust just stabilized its `Allocator` API in version 1.100.0. Definitely worth checking out!
Seems like a long way to walk though. Retrofitting this will take time (if it'll ever complete). Zig made it a core part of the language and library. I'll assume Rust will make it farther than C++ ever made it, but just take a look at how retrofitting custom allocators is going there.
Seems like it will be useful for use-cases like embedded where you're restricted to certain parts of the library anyway. But the battle is kind of already lost for support at the level of Zig or Odin. Even if they retrofitted support for the whole standard library, they'll never be able retrofit all crates or make people even bother adding support for all new crates.
I've been using an arena allocator with embedded C code for a while.
That C doesn't support an arena allocator as part of the standard library points you to everything that's wrong with C. The standards working group.
Also the Intel 0x86 and 32bit architectures caused a lot of issues with C because the paltry number of registers.
show me operator overloading in Zig
In critical low-level code, any kind of overloading - operator or otherwise - is something you'd rather not have.
By expressivity I don't mean what characters you use in the conrecte syntax, but the number of lines needed to express an algorithm (up to a small constant). C doesn't have C++'s expressivity because it lacks templates, and while you can sort of express that kind of thing with macros, it's not all the way there. Zig, however, gets you all the way there (you might need to write matrix_plus instead of +, but the expressivity is the same).
Many people are against operator overloading, imo my only issue with C++ operator overloading is that you're allowed to overload the the assignment operator. From what I can see this is the root of many issues
Is there a way to support varying the meaning of "+" etc without introducing a lot of complexity? I suppose if Zig had nested functions, and the ability to define a nested function called "+", then you could have name shadowing instead of "overloading".
OCaml basically gives you operator overloading this way without actually doing overloading. I'm wondering why we can't have these OCaml-isms in other languages - without needing to use OCaml - which sadly comes with other commitments.
please no
Yes! And exceptions and inheritance and RTTI too. Bring back all the mistakes! Let's party like it's c++99
Regarding the threads I'm seeing in the comments here: it's so frustrating that we have languages like Zig and Nim, among others, which are built for beauty and intuition, but then we have the naysayers that just say "everything that's not Rust or Go is dead because of LLMs, it's over, shut it down and go home".
The ability to vomit out half-baked fragile code at record speeds via plagiarism factories of unprecedented scale with little mental overhead has swung the pendulum so hard in the opposite direction of intellectualism and the human mind. This is why people are depressed about AI. It's a revolution toward soullessness.
Just from the first example:
I think you can represent C better than this. I like to focus on one cleanup block, and exploit the fact that free(NULL) is a no-op. Although note that this assumes calloc(sizeof *u, 1) initializes pointers to NULL, IIRC assuming the bit pattern of NULL is all zeroes is technically against the standard but every system you're likely to target will still work.If you follow the pattern of "it's OK to free NULL pointers", you can also re-use a free function:
Then user_free() can also be a user-facing API function for cleanup, used elsewhere, and it can be written to be cool with tearing down partially initialized structures.All these new languages are unreadable relative to C. If, like me, you like explicit stuff like for (size_t i = 0; i <= n; i++) total += a[i]; all these new languages won't do it.
I don't like this explicitness, because very often it's a lie. In the times of PDP-11 that would compile into a literal counter and literal ADD, DEC, and BNE instructions. Now it will most often compile into some vectorized semi-unrolled form with seven-letter instructions like VPHADDD which add many integers at once, etc.
If I want specific instructions to be run in a specific order, like touching hardware registers, I reach for intrinsics or assembly. If I want an array summed, I prefer to express the intent: total = the_array.sum(); I leave the implementation to the compiler / stdlib.
I feel like every time someone tries to tell me how good C is they immediately end up reminding me of https://queue.acm.org/doi/10.1145/3212477.3212479
Funnily, Zig does allow doing it explicitly like that, just need use while rather for:
That said, perhaps Odin, for which simplicity and readability is guiding principle in its design, is more up your alley. In Odin, can be read: Exactly same style can be used in Go & V (which is/was? quite infamous here in HN). But in all languages, for this example at least, a foreach-like iteration, i.e. would be preferred.You have a point - I find Rust syntax horrible.
C is in some ways minimal, but the pointer-syntax and some more I absolutely dislike. I also found C++ easier to use in some areas, such as:
The equivalent C is simply uglier. Of course C++ failed in other areas big time, but for such simple things like above, I think C++ is better than C. Naturally that cout example is very simplistic, but one can find other examples where C is really quite ugly.puts("Hey there"); is worse than C++ iostream? In my opinion, even printf style strings are better than iostream shenanigans. The main downside of printf is addressed in more modern languages like rust which allow the printed parameters to be embedded in the string so you don't have to keep track of the ordering.
I honestly don't think total = a.sum() is any less explicit than for (size_t i = 0; i <= n; i++) total += a[i]. If anything, a.sum() is more explicit as at least it expresses the programmer's intention explicitly. The loop is one more layer between the reader and the writer's intention, without faithfully reflecting what happens on the bare metal. So it's the worst of both worlds.
A toy example is meant to demonstrate a principle. Toy examples often have alternative ways they can be written, but the concept they are meant to demonstrate requires the whole machinery being employed. Furthermore, how do you think .sum is implemented?
I like doing a mix of either in Nim depending on situation: for i in 0 ..< n: total += a[i]
Sometimes: for x in a: total += x
Sometimes even: foo.foldl(a + b)
Bad ergonomics in loops is questionable design, but that loop in particular isn't better than total = reduce(a, +, 0).
> that loop in particular isn't better than total = reduce(a, +, 0).
it is, in fact, better
It's not very readable. The logic is forced to always use often useless counters and check them, even on the syntax level. I will take any for each mechanism over the loop style. Map, reduce, fold, all better than having to write counters and the check for it.
Rust will take over all these niche languages anyway. Yes, Rust is a viable replacement for C and C++ in the long term. Zig is just trying to be a middle ground, which we've established doesn't work. Zig is particularly irrelevant compared to Rust in the LLM era.
I can tell you've never written any low level stuff in Rust. When you get to the absolute lowest level of programming, there are tings the compiler cannot prove. Which makes you use unsafe Rust, but that doesn't turn off the Rust compiler rules, so you are forced into this awkward way of programming just to side step the compiler rules. Graphs, linked lists and caches are so painful to write in Rust.
That's overly confident. When I see Rust code, I'm immediately reminded of Scala and how it was supposed to take over the JVM world, but did not, and Kotlin, a much simpler language, is getting more and more popular. You might claim that LLMs have no problem with that kind of language complexity, but people still need to review stuff. I have no doubt that Rust will reach C++ level of popularity, but that still leaves a lot of space for other low-level languages.
Scala "failed" for two reasons: Firstly, (like Haskell) it quickly exceeded its weirdness budget, and cultivated a community that embraced and sustained that weirdness. Secondly, a number of prominent individuals publicly expressed political views that made it hard for engineers in "mainstream" organisations to loudly promote Scala.
I think Rust is doing much better on both fronts. It has always been a more pragmatic language than Scala, and the way it is developed supports that, rather than pushing the weirdness budget higher. The overall political lean of the Rust community is also more amenable to support in mainstream institutions + companies.
Those advocating for the take over always forget, every single time, that they are a guest language, those developing the underlying platform have zero interest into taking their desires into account.
These even applies to C++, born on UNIX out of C, and regardless of rants, it is 100% obvious to me that there wasn't a single UNIX platform that would care to use C++ instead of C on its core implementation.
Middle ground? How do you figure??
Zig is so clearly not trying to do anything rust is doing, I don't really understand how you could come to this conclusion.
Zig is "I want to tell the computer exactly what to do."
Rust is "I want to write code that protects me from myself"
Zig's C compiler is super handy for cross-compiling Rust
> Zig is just trying to be a middle ground, which we've established doesn't work
We did?
> Zig is particularly irrelevant compared to Rust in the LLM era.
This. If we continue on this LLM/AI trajectory, and you're not constrained by your platform to use a specific language, why would you choose C or Zig or C++ over Rust? You won't be reading or writing the code yourself, LLMs will, and they benefit from a strong type system that catches a lot of issues, meaning fewer tests are needed.
Why can’t the LLMs avoid the memory issues entirely?
That sounds boring and soulless as fuck..
Not really, Zig takes the exact opposite stance as Rust for correctness.
Rust is the language defending itself against human mistakes whereas Zig promises the dev/agent total freedom by eliminating implicit interactions. That makes zig more readable/approachable without needing large amounts of context.
Are all programming languages which initially to be ergonomic to humans (Rust included) irrelevant in the "LLM era"?
All the programming languages that didn't already have enough inertia when Claude Code came out will be irrelevant.
Except for rewriting LLVM it depends on for its compiler implementation.
AI is also a great tool for C and C++ development, especially when writing English to C/C++ compilers.
D and Nim have had the same features for years btw.
https://github.com/nim-lang/nimony
Check out Nimony effectively Nim 3.0 from the author. It's a top to bottom rethinking of Nim with all the lessons learned. I'm so hyped about it tbh
https://nim-lang.org/araq/nimony.html
If they can get the tooling situation handled better with 3.0, Nim will be probably the best all-around programming language in my book. The only reason I tend to opt for Zig instead (and the reason the library ecosystem is pretty small) is that it just feels a little unpolished all over the place. But the core principles are just so good.
I don't mean that as an insult to Zig. Zig is amazing. But the ergonomics of Nim are just unbeatable.
Intriguing. How usable is it right now?
God I loved playing around with D back in the day when I was in high school. It seemed like a no-brainer that it was going to be huge. It's such a shame it never took off. Incredible language.
It's so damn nice, its a shame it's never taken off the way it could. I think there's still time to make it attractive to companies, but with people's increasing use of AI I don't think anyone even cares what language their model writes in, look at the insane uptick in Rust programming.
Be it a lesson that having an adoption lever matters.
It’s pretty obvious why they didn’t, they’re GC by default. That’s already enough to put people off, even if it’s “not a problem” in reality, people will just avoid it for systems programming if they hear that, they will assume all the good features need the GC
Nim is stack allocated by default, and you annotate types explicitly with `ref` to use the GC. Even then, the compiler elides reference counting using borrow checks, you can choose different GC options, and the GC isn't stop the world like most. You don't need to touch reference counting if you don't want to, and Nim fits embedded dev pretty well for that reason.
Many GCed languages have any number of useful features. But when the discussion is focused on systems programming, they are quite off topic.
I like both of those, I like the idea of Zig, it does seem to be striving to be pure in some areas where C is "king" that other languages gloss over, but Zig is always changing, and its got some elitist people in its ranks that left me not wanting to bother with it. Imagine a programming language maintained and used by geohot clones.
> Errors you cannot ignore
It's okay for me to declare a macro with `__attribute__((warn_unused_result))` for GCC and Clang, and `[[nodiscard]]` when the C code is later compiled with C++ (or nothing).
[[nodiscard]] is in C23.
I've been toying with the idea of learning zig and weirdly enough I was looking at this guys book. I don't have any experience with low level languages. The closest I've gotten is Go.
I was debating between C and Zig, but I still don't really know what I want to choose. Feels like C is probably the right choice given the languages age and it could technically be more useful (not that I'd be looking for a job doing C work).
For those that know both, what would you pick?
C is still supreme for working on the majority for a Linux/BSD system stack. It also imparts skill that transcend to most other spaces where you may eventually need an FFI to interact with a library anyway or understand how it actually runs on a system.
It depends for what you want it. If you're going to do an API, well, Golang is more practical here in my opinion. For TUI apps, I would dare to say Rust was more pleasant than Golang. My experience with Zig was limited, I would not say is not a good fit.
I would say from a pedagogical perspective, learning C is hugely useful for understanding how programming works at a much lower level.
This has the benefit of you learning about manual memory management and how to deal with all the issues that come with such a rules free language like C that will basically let you do anything. This understanding means lot of the constraints and features that safer languages like Zig and Rust add start to make a lot more sense. For example, going from Python to Rust, the borrow checker will probably seem rather arbitrary, but going from C to Rust, you will find the borrow checker is just automating a lot of checks you were already doing yourself.
TLDR: Learn C. I would recommend the 15122 CMU course as a pretty good foundation. You can find it online here https://www.cs.cmu.edu/~15122/schedule.shtml .
For that matter, assembly is useful as well. Not that you have to become an expert in it, but do enough that you understand it from a practical standpoint. It doesn't even have to be on x86, use an emulator of something simple like a 6809 or 6502. I never had trouble understanding pointers in C once I had some experience writing assembly code.
Another quite good one is Modern C from Jens Gustedt.
https://www.manning.com/books/modern-c-third-edition
This is the kind of book to learn C from nowadays, not a dusty copy from K&R C, leave that one for historical purposes only.
I think you should know C if you want to do low level stuff. It will help understand why zig (or rust) is built the way it is and what is useful about it, too.
Yeah
The lack of a native slice is the most glaring C fault I think exists
(And of course the committees won't implement it, and of course C is going to remain broken)
You could help? https://www.open-std.org/jtc1/sc22/wg14/www/contributing.htm...
But I am also quite happy about how far one already gets with variably modified types and a custom span type: https://godbolt.org/z/rPen5Movd
I don’t get it, C arrays can be used as slices, no?? Given a pointer and a length, which is how C does any array, works just as well (I mean if you consider arrays without a length a fine thing) as a slice!
Sure you can do that, but you end up having to re-implement all of the standard library functions that expect to work with zero terminated arrays.
And Dennis Ritchie even proposed one possible approach.
C is far behind the sate-of-art in C and Go families. True, but not bad.
It is what it is, but can work on what it already has, while keeping its tradition. Small changes, add common extensions, conservative additions, improve coherence and correctness of the standard while keeping easy to implement and small.
No crazy things.
Keep in mind that it is standardized and targets things others do not target.
Is Zig stable yet? No.
I like Zig but having to fix a bunch of version issues each time I touch an old zig project of mine really put a damper on my enthusiasm.
I like the idea of Zig too - "better C" sounds just up my valley - but the actual implementation leaves a lot to be desired.
to save your enthusiasm, tell your clanker to fix version issues instead
AI slop. Every article on this site has "The honest tradeoff" as a header. Looks like it was generated to promote a book which is no doubt also just slop.
I don't know if this Zig over C article is generated, but the Zig over Rust one [0] is painfully AI-written.
I'm not ideologically against AI, but I'd certainly not buy a book from someone who needs to use AI to write an article like that...
[0]: https://www.mtsoukalos.eu/2026/04/why-zig-over-rust-for-syst...
How can you tell? I just scanned it but it doesn't feel like being generated.
Pangram says 99% AI.
https://www.pangram.com/history/5f3d749c-713c-447a-82cc-d3a6...
Up until about a week ago, I had no sympathy for people complaining about "AI writing style" in articles - and then all of a sudden it hit me. Kind of like unexpectedly developing an allergy to sawdust.
Doesn't read AI generated at all.
The prosody and the headline style is a dead giveaway but compared to other AI generated text this article is far more tolerable.
Meanwhile no one's pointing out any technical errors.
> Every article on this site has "The honest tradeoff" as a header.
This is a hallucination. I'm sorry. This is what we call these kind of statements these days. Unless you can prove your humanhood, that's how it is now.
I wrote recently about a weird issue I encountered with Zig, though to be fair it was related to using Zig to compile C code, humorously in a Rust project (which touches on all of the languages mentioned in this post).
https://dennisforbes.ca/blog/microblog/2026/10/the_accidenta...
While I did just dismiss it as an edge issue, it turns out that this same rather clumsy sort of mistake has happened repeatedly in Zig's pure rewrite of MUSL. And despite being an absolutely catastrophically bad problem, by my judgment, the problem is still in main at this moment, across a wide number of musl function rewrites.
Which gives me pause about the whole zig project. If you're rewriting a critical library, making such simple but consequential mistakes shouldn't happen, and if they do happen it should be a red alert type situation.
When working with Zig, you are a beta tester. The development process is unfortunately not great, so bugs slip in fairly easily. You need to be ready for it and test your application properly. Large Zig projects don't target the latest version. That said, if you can deal with that, you get a great language that is fun to use and very practical. I think it's worth it, even if it can be frustrating at times.
I agree Zig can be fun but for real projects people should stick with Rust or even D which is just as fun!
Why not adding the link to the issue in the blog post?
https://codeberg.org/ziglang/zig/issues/37402
Looks like it is being worked on.
Personally I think it's not that catastrophic for zig < 1.0. Just a performance regression, and one can always link to other libc implementations, or is their own implementation enforced now?
If errors like this are acceptable because of the version number of an otherwise decade old project, then that's ample evidence of why Zig is not ready and should not be used for any software that needs surety.
Zig can be a hobby/learning project (in which case these elementary mistakes, and the lax development process that allowed them, are totally acceptable), or it can be a project that targets critical applications (like TigerBeetle, which handles REAL MONEY), but it can't be both.
strchr has no time complexity guarantees, by the way. This behavior is strictly correct.
The best kind of correct!
> Which gives me pause about the whole zig project
The whole zig project is like six people in a trenchcoat. You can't expect them to prioritize your one thing after 3 weeks
Did you make a PR?
I'm not the poster, but I found the related issue:
https://codeberg.org/ziglang/zig/issues/37402
It isn't my thing though. It's quite literally, by choice, their thing. They are the ones who decided that rewriting musl in zig was something they need to do and was such a priority. Only it's a serious regression.
But I mean, the six people in a trenchcoat comment is basically precisely what should give people pause. In my project I simply eliminated zig from the stack entirely because even if I worked around the problems, what comes next? What's the next showstopper that gets waved away as oh well six people in a trenchcoat...
Eh, whatever.
If their resources are so limited, why have they decided that rewriting libc from scratch is a top priority?
Andrew Kelley had a comment re this bug over at lobste.rs:
> I made the judgement call to let this slide in the review. I'm still not sure whether it was the right or wrong call.
https://lobste.rs/s/lh1j0e/shlemiel_painter_is_back_how_zig_...
Interesting read.
For what it's worth, coming from an era where it was trivial to cross compile, I can't help but think that the real issue here is:
"C is not going away and I still read a lot of it, because the UNIX source code and most system libraries are written in C and their man pages document them with C prototypes. But for new code I choose Zig."
Has this aged well though?
The TechBros pour in tons of money into "agentic programming" or "agentic workflows" right now. You can see that all over the place; OmarchySlop and other AI-controlled projects, where Claude is now the main designer. So in such a scenario, where does Zig really fit in? The "but for new code I choose Zig" is not a really compelling argument IMO. It reminds me of the issues that D has ("we are the better C++!!!" or even Java too). It's interesting that so many languages try to replace C. All failed, IMO. And C is still a pretty bad language. For instance, I think almost everyone would concede that crates in Rust are useful or good; C++ kind of submitted to this and has their own variant now as far as I know. C does not - or perhaps it has but almost nobody would know it.
I kind of want a language that really sits like in both camps: compiled, and scripting use. But each language seems to just fail hard in one area. Including syntax-wise. Complexity-wise too; I find Rust annoyingly complicated. Go is in many ways simpler than Rust, but it sucks in other ways. Of course there are always trade-offs either way, but I kind of want a language that can offer insane speed while having a great syntax (crystal also fails here; it is fast but the syntax is pretty bad. Why is "alias xyz abc" not working? It's so easy to support. But anyway I could go on for years here.)
My goto language for both fast and still scriptable is Dart. They invested a lot in UX and performance in the last few years and it shows. Run as a script or compile to a small binary that runs pretty fast, similar to Go performance as as as I have bothered to check. Best DX out there even if you don’t care about Flutter.
Check out Mojo, a compiled language by the creator of LLVM with Python syntax.
As long as every new language goes to great lengths to compare itself to C ...
I'm going to keep using C.
Its in my AGENTS.md file.
cynical take, but I like being employed. So it's C++ for me
[flagged]
[dead]
[dead]
Zig will never be successful.
Why so?
Their rewrites of all security critical libraries while also refusing to use AI which at the moment is surfacing huge vulnerabilities all over the place.
And of course it needs to get to stable first