438 points · by Tomte · 5y ago · 278 comments
> soon we’ll also have a package manager
This. If they succeed to do this (and I have my doubts) it will be a paradigm shift for low-level "system" programming.
Let's hope this is not vaporware.
Finally, it's relatively easy to contribute to Zig. Andrew Kelley is very opinionated on where the language should go with an emphasis on simplicity which sometimes can make things awkward but he is also persuasive and welcoming. I have been using Zig for a month and I am still positively surprised so he must be onto something.
[0]: https://github.com/ziglang/zig/blob/master/lib/std/json.zig#...
I sincerely approve of the skepticism. I can assure you there is already a very large fire under my ass to get this shipped.
To provide some more context, here is a snippet from the latest release notes[0]:
> Having a package manager built into the Zig compiler is a long-anticipated feature. Zig 0.8.0 does not have this feature.
> If the package manager works well, people will use it, which means building Zig projects will involve compiling more lines of Zig code, which means the Zig compiler must get faster, better at incremental compilation, and better at resource management.
> Therefore, the package manager depends on finishing the Self-Hosted Compiler, since it is planned to have these improved performance characteristics, while the Bootstrap Compiler is not planned to have them.
I can't help but mention, I am incredibly excited about how well the self-hosted compiler is coming along. Progress is swift, and all the ambitious design decisions (fully incremental compilation[1], extremely fast debug builds[2], low memory usage, multi-threaded) are intact. I anticipate it to make quite a splash once it becomes generally usable.
I don't expect the package manager to take nearly as long to develop.
[0]: https://ziglang.org/download/0.8.0/release-notes.html#Packag...
[1]: https://vimeo.com/491488902
[2]: https://twitter.com/andy_kelley/status/1416485475125141504
I'm going to check out Zig because of your response.
I love coming across comments like this one on HN.
I wrote about cross-compiling to a raspberry-pi and writing a barebones driver for an OLED display[^1]
That was a lot of fun despite the fact the code was incredibly basic. The interop with C was effortless.
[^1] https://www.kamelasa.dev/posts/gettin-ziggy-with-it-pi-zero....
ahem
> Progress is zig ...
Thanks for all your work! I ported a bunch of basic data-structures from C++ to Zig very early on (right as y'all began exposing generics). Even though the code no longer compiles, still worth learning The Zig Way™.
If I may, my only piece of feedback (as someone who looked at Zig with fresh eyes) is that the syntax has lots of special chars (@, !void, .{}, &, etc). Is there a rationale published for these and other design choices (even if it's "I like it that way"). I would have expected a language with ambitious goals like Zig to take a stab at coming up with a grammar that's even simpler and cleaner than C.
Regardless, getting a new programming language working, noticed and used is monumental effort, so I wish you best of luck with Zig!
Relative to c, though there are imo fewer special chars:. Zig adds ! and ?, Which are there for really good reason, but subtracts for example <> and #.
The hardest thing is the . syntax for anonymous structs and tuples, but to be fair it is very consistent, and so many times I'd think,"hey I wonder if..." And then try it with the syntax and of course it works.
That is sadly my gripe with a lot of the newer languages too. I have been looking for something to replace C for a long time, something that makes it easier to not shoot yourself in the foot. I just find most of them significantly less readable than C.
Rust seems to be going down the route of C++, hence I do not deem it a safe language at all, as I have an exceedingly hard time parsing the source and figuring out what is going on.
Zig is WAY better in that regard, but as OP mentions: all the special characters make things more difficult to parse. Calls like these (taken from the introduction page) contain so much visual clutter:
try expect(@call(.{}, add, .{3, 9}) == 12);
I sadly doubt any of this is possible to change at this stage anymore. Zig definitely seems the most promising C replacement with regards to tooling, especially cross compiling and C interop are a breeze. Truly inspiring work!The only new C-like language that really nailed it for me syntax wise would be Nim. Very clean and easy to reason about, which - from a programmer perspective - makes it exceedingly safe to program in. It just seemingly lacks most of the safety guarantees that the compilers of other, newer languages provide.
To make things a little more interesting though, Zig's shape in this regard should be roughly congruent to C's, so you should be able to do anything with Zig that you can with C. This includes linking against shared objects for C libraries like, e.g., SDL2[1] or building mixed-language Zig+C projects[2].
0: https://ziglearn.org/chapter-3/#packages 1: https://dev.to/fabioarnold/setup-zig-for-gamedev-2bmf 2: https://tiehu.is/blog/zig1
https://github.com/ziglang/zig/blob/master/CONTRIBUTING.md
Though I’m interested in hearing from the creator itself as well.
How will you verify the chain of trust?
The only thing I've found being a pain point is C's biggest pain point: the lack of a proper string type. Even though I've worked for years in the past with C and C++, I still get tripped up, and in Zig I keep on being confused whether I should use raw byte arrays, or sentinel-terminated arrays for certain string manipulations. Maybe I'm not familiar with common idioms in Zig that might help avoid this C-style tracking of string/buffer lengths malarkey that I tend to end up with where a slice is not appropriate.
Maybe a dynamic-length string library is the way forward.
I've always tried as much as possible to treat strings as just opaque data and never look into them, which tends to work well, but in some domains you really need to look at and massage the characters/codepoints/grapheme clusters, and the lack of a first-citizen UTF-8-aware string type is, I think, a bit unfortunate in this day and age. I understand having one of those could make C interop a bit gnarlier (I think Odin's approach of having two separate string types -- one of which is just meant to be used for interop -- should be workable).
Oh, and the ecosystem of libraries is still young. I needed to format timestamps as human readable date/time to a file, and had to step down to C to do something that basic[1], but it'll get there in time, I'm sure.
[1]: "basic" from the perspective of the end-user of the language. Having written a (not even fully featured) date/time library in C++, I consider date and time to be one of the hardest domains I've ever had to work in.
Then again, I'm not sure exactly what a type would be for Unicode. Basically just a flag that the array of bytes has been checked and is valid? It's nice to let the type system help you enforce your application boundaries, but I think you could wrap it pretty easily in a struct of your own if you needed that.
[0] https://github.com/ziglang/zig/blob/master/lib/std/unicode.z...
In something like Zig I think it's OK that it's merely a stated assumption that these bytes are UTF-8, not actually checked - so long as people take that seriously.
It's nice in code that maybe isn't very concerned with such things to be able to know that any "string" is actually text we can display, output to a console, something like that. Not for example a TCP/IP packet we haven't decoded yet, or the first 32 bytes of a JPEG image.
Programmers who aren't writing firmware for a vacuum cleaner or washing machine, probably want string literals like "this" in their code, and you'd naturally want those to have a type, for which a string type is the obvious fit. I believe in 2021 this type should obviously be UTF-8. "It's just some bytes" is far from useless, but it isn't much of a string type.
I was sceptical at first about Rust's choice to build in str (immutable UTF-8 string slices), because that seems like a relatively high level concept. But unlike std::string::String, str isn't that tricky after all. See, the only place such things would come from (not having std::string::String to make new ones) is the program source, and our compiler is necessarily already reading the program source, so it follows that the compiler must know how the source is encoded etc and thus it does actually know exactly what those literal strings are. If your literal wasn't Unicode, that wasn't a Rust program and it won't compile.
I have this internally in my lang AST Rust
Utf8
I think that is the type: struct City {
name:Utf8
}
For a scripting lang like mine I surface it as `Str` but in a system language I think is better to say `Utf8`Well, as you said "Unicode is quite large and complicated".
And in 2021 it's not just anglosaxon software users anymore (if they ever were), good unicode lib if not type is a must.
You don't need a string type for that, you just need routines that handle UTF-8 strings, like utfcpp (https://github.com/nemtrif/utfcpp).
I was doing some pretty gnarly high-level filesystem work (transforming an unstructured tree of files/folders into a more structured tree following certain naming and categorization conventions -- a lot of parsing/building/concatenating paths). I have been working with higher-level languages for the past decade or so, but have had a wanderlust to get away from garbage collected langauges and go back to my roots a bit, so I've been comparing some of the newer options in the "improved C"/"C++ replacement" space.
It may very well be that I'm not the target demographic for Zig, and that's totally fair, but to me it felt pretty jarring to go back to working with C-style character (byte) arrays and all the (well-known) issues with which they are fraught. I didn't feel like Zig was an improvement over C in the string handling area (as opposed to all other areas), whereas languages like Go and Rust are.
Other than that, I felt Zig was a joy to use.
For a minimal std, maybe Zig can have a standard `str` type which is used for all functions that don't need to grow the string and the `String` type is provided by any 3rd party library which is expected to provide a conversion function from `String` to `str`.
These strings types could or could not have a requirement of being Utf-8. Maybe there is a builtin wrapper to convert them. So you can any dynamic byte array which can be converted to `str` (just a pointer and length, no validation) which can be later converted to `utf8` (str but validated). A `String` which guarantees Utf-8 could directly convert to `utf8` to save validation costs.
I don't think that's the parallel I would draw.
Rather, I think both Zig and Rust aim to serve the use cases C and C++ do, but Zig and Rust pick different points on the tradeoffs involving safety. Zig feels like a "better C", in the sense of bringing modern language features to C, but it chooses safer rather than safe. Rust supplies modern language features as well, and chooses to prioritize safe; sometimes that comes at the expense of other factors, such as productivity or compile time. I personally prefer the point on the spectrum that Rust chose, but I think Zig still offers improvements over C.
One thing that impressed me about Zig is how simple the language is. I get the impression that it would take very little time to properly learn the language and become effective at it.
Rust, on the other hand, has a whole lot of complexity even without the ownership semantics. So much to learn and understand. And, in some cases, work around. It seems, from looking at others' code, that there is a very strong temptation to lean on `unsafe` instead of figuring out how to solve a problem within the constraints it normally applies.
That has me wondering if there's really all that much safety difference in practice? Simpler code is generally easier to understand, and it's generally easier to find and fix bugs in code that's easier to understand. I can imagine a world where it's a tradeoff between, "You definitely won't have any of this relatively narrow category of bug, unless of course you opt out of the static checks, which you will probably do sometimes, even though we tell you you shouldn't," and, "There are no particular guarantees, but you're generally less likely to have any of this broader category of bug."
The biggest difference in the problems they solve, in my view, is that Zig does not aim for safety. It'll be easier to write safe programs yourself with Zig than it might be with C, but it doesn't give you any guarantees.
Zig also seems like it may be a better fit for embedded programming; there's a big community around embedded Rust, and it sounds like there's a lot of progress, but still an uphill battle.
But yes, Zig:Rust :: C:C++ has merit in that Zig is a much smaller, less feature-rich language.
The issue with this analogy is that it assumes that C, one of the languages used in the most diverse set of circumstances ever, means the same thing to everyone. Same with C++, frankly.
There's definitely something to that analogy, but I think it also misses a lot of really important details. For example, Zig has generics, which right off the bat makes it hard to say that it's "like C". Also Rust enforces memory safety, which isn't like C or C++.
Of couse, it's a much less powerful feature, there's nothing like interfaces or stuff, just a way to "overload" based on the type.
I feel like Rust wants to replace C but it also wants to replace C++. And given the complexity difference between the two languages, that means that Rust will end up closer to C++ than to C.
So there's some overlap based on how Rust positions itself, but not based on how Zig positions itself.
Rust wants to make systems programming memory safe (and type safe while at it). It's not really about any specific language, it's about dragging the field forwards on the safety front.
Well it's not really Rust, it's the Rust community, which kinda wrestled it away from Graydon Hoare: the original inception of Rust was more of an applications language (what with the evented model and the split stack and the planned-though-never-really-implemented GC'd pointers) — which explains part of the historical confusion with / comparison to Go.
But then a critical mass of people took a look at this early rust and figured "we've got plenty of memory-safe and type-safe (ish) languages for applications, but this thing has precise control over memory and lifetimes and shit, we could actually build reliable infrastructure with that", and it coincided with a lot of memory safety issues news (which has been continuing ever since), and the rest is history, pretty much.
> Zig is a general-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
I'm imaging some poor software engineer in 2065, having to maintain an enterprise legacy stack... levels of FORTRAN/COBOL->C->C++->ZIG->RUST->PERL->PYTHON.... all the way up....JS..etc..
The ZIG compiler requires a C compiler to compile to a native executable though.
One thing I wish the blog post had brought up is testing! Zig has some great tooling around tests, and that is something sorely lacking in a lot of C projects. If nothing else, you can pretty easily use Zig to simply write some tests for a C project! Even that would be a big improvement to the ecosystem.
I feel like the notoriety that C++ gets for it's absurd complexity comes not from variadic template metaprogramming/rvalue references/unique_ptr or whatever, but the absolutely humongous effort needed to understand automake/CMake/autotools just to build other people's code (god forbid on a different platform than the original author).
I'm working on a game engine in Zig[0], and I've been able to package up GLFW, write a build.zig file that `git clone`s all of the third-party system dependencies so that anyone can just:
const glfw = @import("glfw/build.zig");
...
lib.addPackagePath("glfw", "glfw/src/main.zig");
glfw.link(b, lib, .{});
And have GLFW building (and cross-compiling!) for their project, without installing anything other than Zig and Git. No XCode. No `apt-get install ...`. Nothing. Just `zig` and `git` binaries. Zig is the C compiler and builds the GLFW source, and I have repositories with the required prebuilt system libs for cross compilation.But the stack of stuff it takes you supposedly need to get stuff to compile is often insane. On one project I demonstrated that just find . | grep ".c$" | xargs gcc ... and a final link ran significantly faster than the mass of recursive nested/fake/etc makefiles that were supposed to speed up the compiles by doing dependency computations. I remember showing someone the basic "we turn the .c files into .o files, and then we make a second pass to link 'em" and they were like "really? that's all there is to compiling a C program?"
The real straw for me when I was contributing to the Cairo project was recognizing I was going to have understand this stuff more, and so I sat down and read the Make manual: 16 chapters. Now I need to understand Automake, read the manual: 26 chapters. And then Autoconf: 21 chapters. It was like it was just spinning bigger and bigger.
And even better since they support binary libraries, I can focus on my own code instead of building the foundations first.
Well yes, that would kill me too, if I actually expected the language to come with a single blessed dependency that addresses functionality <Foo>, that I will never want or need to patch the blessed dependency, and that there would be only one way to actually build a program or library.
But it doesn't kill me because I don't expect either of those things.
The dependency stack for my (21 year old) project consists of 86 3rd party libraries that on an x86_64 platform take up about 2GB after compilation. This is intimidating and sometimes painful, but I don't find it insane in any way. We have patches for a half-dozen of the deps that will never make it upstream and we have to be sure that we compile the libraries in the precise way that we need them (for example, we require the thread-safe version of libfftw, not the regular version).
> To me it's the clear choice if I'm going to rewrite an old C project since I can mostly just copy paste the old code and it runs
With the new ImportC feature you can literally copy-paste the code and reference your C types from D directly with a mixed compilation.
https://news.ycombinator.com/item?id=27872596
https://dlang.org/spec/importc.html
Quoting Walter from the thread linked above on it's purpose/reasons (which I think ought to go somewhere official tbh, since that brief discussion in the above thread is the best + most succinct overview of it currently AFAIK)
The reasons for ImportC are:
1. It's no longer necessary to translate .h files to D to interface with C. While doing the translations isn't hard, it is tedious, and if there are a lot of .h files it becomes a barrier.
2. .h files get updated over time, and correspondingly updating the D files is error prone. It's much more effective to just compile the new .h files.
3. It is not necessary to even create a .h file - just compile the .c file with ImportC and D will access it just like any other module. D will even inline the C functions in it.
4. Use it as a standalone, small and fast, C compiler.I have written small applications in both. To be transparent: my total dev hours in D are probably somewhere around ~100, and in Zig about ~30.
So I am more familiar with D than Zig, though competent enough with both to have written a few small real-world programs.
> Its interoperability with C at the source and object level is first-class
D has direct interop with both C, and C++. Also, it's recently gained it's own C compiler, and can natively compile C code so that they are D objects, not just external definitions.- https://dlang.org/spec/interfaceToC.html
- https://dlang.org/spec/cpp_interface.html
It can even directly interop with C++ classes:
- https://dlang.org/spec/cpp_interface.html#using_cpp_classes_...
> the syntax was very easy for me to pick up as someone familiar with C/C++
D is closer to C/C++ than Zig IMO. One of it's design goals is actually: "10. Where D code looks the same as C code, have it either behave the same or issue an error."
And: "The general look and feel of C/C++ is adopted. It uses the same algebraic syntax, most of the same expression and statement forms, and the general layout."
See: https://dlang.org/overview.html#goalsI found Zig to be much less syntactically similar to C/C++ than D. Zig felt more like a mix of Rust/Go.
> the features it adds on top of C (e.g. slices, compile time execution)
D also has slices and (outside of Lisp) was the first programming language I believe to introduce CTFE and CTFE-based metaprogramming. C++'s implementation as I understand it is essentially lifted from D.- https://dlang.org/articles/d-array-article.html#introducing-...
- https://tour.dlang.org/tour/en/gems/compile-time-function-ev...
> its translate-c utility works amazingly well at transpiling C code to Zig
As stated above, not required due to ImportC, but there are several tools to automatically generate "extern" bindings to C/ObjectiveC/C++.You use these if you're linking with an external out-of-tree library, or a C++ library.
- C, Limited C++ = https://dlang.org/blog/2019/04/08/project-highlight-dpp
- C, Extensive C++ = https://github.com/Superbelko/ohmygentool
- C, Objective-C = https://github.com/jacob-carlborg/dstep
> its test blocks make unit testing trivial to integrate.
Again, D also has this:- https://tour.dlang.org/tour/en/gems/unittesting
=============
Not trying to start a pissing match, because I actually think that Zig has a lot to offer as well -- but for these particular list of things, there's no clear winner here.
Zig on the other hand seems like a silver bullet aimed straight at C's heart, the embedded space. Once it arrives it'll only have to worry about Rust.
Rust is the black hole at the center of the software universe, slowly sucking the blood out of everything else. Zig vs Rust is shaping up to be an epic battle, like the Jedi vs the Empire, for sure :)
headline from that website: Zig is a general-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
Zig is a system programming language, whereas when someone says general purpose programming language they mean java or python. And "robust, optimal, and reusable software" - this type of words are used by all projects these days that it sounds like MBA speak.
I also don't like the tendency of system language projects (zig, rust) to market as if they are application languages, perhaps in an attempt to drive adoption. Can't blame them for this, but it seems an influx of relatively young, inexperienced programmers from ruby rails / javascript crowds creates false impression of a strong ecosystem.
Zig's cross compilation stuff and general compiler features, that this post talks about, is excellent, awesome, and makes me quite jealous frankly.
I actually got annoyed with this enough that I started doing a quantitative analysis; if you look at the canonical repository tracking this, it's got 44 total issues, most of which are jokes https://github.com/ansuz/RIIR/issues If you search GitHub for issues with these words in it, you get some, but many are either obvious jokes, people making issues on their own projects to think about doing this, and things like that. I never followed through on collecting it into a blog post though.
I didn't think your writing was inappropriate at all; memes are memes, and I'm convinced that this one is just never going to die, because it's taken a life of its own, regardless of the underlying truth or not. It is always worth pushing back on this sentiment, even if I don't think Rust specifically tends to actually embody that sentiment very much.
(Also: I don't know why you're now being downvoted. Hacker News works in mysterious ways.)
https://news.ycombinator.com/item?id=25198571
Someone reposted the same document with Rust replaced with "$hotlang" which, for a reason you can guess, wasn't flagged at all:
https://news.ycombinator.com/item?id=25208313
My impression is that there are more than a few Rust developers who dearly believe in rewriting in Rust and were sincerely, bitterly offended by a joke to the contrary.
I rewrote 'leakdice' as part of learning Rust, so arguably that doesn't count (though I had never rewritten a program to learn a previous language), and 'misfortunate' wouldn't make sense in unsafe languages so that doesn't count either, but I then also immediately began rewriting 4store in Rust.
I had never been compelled to rewrite stuff in other languages I learned. I am a compulsive programmer, so I did write stuff in languages I learned, (the other day I re-discovered, via an enquiry to a very old email address, that I used to know Scheme, as evidenced by the fact I wrote some Scheme that they were asking about from last century) but I didn't rewrite anything until I learned Rust.
C. Go. Python. Java. PHP. Bash. Perl. C#. Early C++. I'm sure there are many more. But always new things, either because the language afforded something I hadn't considered before or more often I wanted something and I chose a languages I knew would be able to achieve it. That's why I wrote some PHP less than a year ago, I'm not proud of that, but PHP got the job done so that's what I did. I can report that modern PHP is merely a bad idea, like Javascript, which I probably forgot to list above.
Anyway with Rust I not only wanted to write new low-level code in Rust, I looked again at C programs I use and thought, "I should rewrite that in Rust". It felt like a good idea, and I expect to follow through on it at least somewhat, let's see how long 4store takes.
And I'm one that will be super-happy if all C/C++ code in the world dissapear now and be replace by Pascal/Rust/Zig/D/anything else that is better.
MOST of my troubles are because C/C++. And the worst ones. Even if I 'm in a environment (business apps, ERps) where in theory system lang concerns are a distant worry.
I guess the other (simpler) alternative is to wrap Zig into a Cargo package, similar to this:
I have been talking about how much I would love this to happen, but I can't do the work myself. Frankly, I don't contribute to the compiler, so even getting up to speed would be a ton of work I just don't have the time for.
* The collection of headers for various targets, and the tools to upgrade/maintain them.
* The source files for various libcs, patches, instructions/tools to upgrade/maintain them
* A declarative set of instructions to create build artifacts (not Makefiles!!)
* Instructions/patches needed to integrate Clang driver frontends into a different binary (making the "main" functions co-exist peacefully).
Would be a fair amount of overhead to collaborate, but perhaps could ultimately save both parties labor.
"I think he said, 'No way?! Zig for the win!'"
In some way, you could say that Zig is pulling system programmers towards high-level programming, whereas Rust is pulling high-level programmers towards system programming. That's not a watertight comparison but I think it's an insightful one.
and that's ignoring the nightmare of cross-compiling with gcc.
andrew kelley has talked about this[1]. his main point was about the number of dependencies you end up with compared to zig, where the standard library includes a high-level build system api. so your zig build scripts are written in ziglang and run by the zig compiler. no extra dependencies.
(embrace, extend, extinguish) for those not familiar
Second, "extend" has traditionally meant "extend with proprietary code". Think early 2000s Microsoft with browser APIs and J++, or Amazon with their in-house forks of MongoDB, PostgresQL, etc.
There's plenty of innocuous activity that could be called E3 if you stretch the definition that far. Most of the GNU ecosystem for example.
Explore, Expand, Exploit, Exterminate
While Zig is manual memory managed like C and nearer to the core, but harder to program.
"Nim is a statically typed compiled systems programming language."
As someone else pointed out, when using Nim with its ARC/ORC and move semantics (which will eventually be the default), it's closer to Rust than to Go.
That being said, Nim's current default GC does well for many kinds of workloads. If it's really causing a performance problem, it's possible to disable it and manage memory manually (or use a different language for the task at hand, of course).
I don't do C/C++ development. How many headaches would using Zigs compiler & build system solve?
Truth is that cross compilation always breaks down in complex deployment use cases.
I think the problem for Zig is that they use MinGW as their Windows target, and the latter's standard library isn't really UWP compatible (yet?).
Zig uses LLVM for cross compilation, and so does clang. It's really not any better.
First, Zig has a pretty unique and impressive build&caching system. It makes something like this a lot less painful than it would be otherwise. It makes it practical to just download a 40MB tarball and get full cross-compiling from it.
Second, clang itself isn't in the business of building a distribution of itself + third-party libraries. Usually developers using clang get such libraries from their "vendor" (package manager if on a Linux distro, Apple if on MacOS, etc.). And those vendors naturally focus on their own platforms. So Zig ended up the first to really do the work to build a cross-platform C/C++ toolchain.
People without incentive usually do not do this tedious kind of work, since "it works for me".
Not true. Unity once supported their own language based on Boo, a python dialect for the .net runtime, that they falsely advertised as "Javascript". That has since been depreciated.
My understanding is that `zig cc`/`zig c++` are thin wrappers around LLVM, so doesn't that just reintroduce the same problem?
clang cross compilation is not really any harder, you just supply the -target flag.
> If zig cc is built on top of Clang, why doesn't Clang just do this? What exactly is Zig doing on top of Clang to make this work?
> The answer is, a lot, actually. I'll go over how it works here.
[1]: https://andrewkelley.me/post/zig-cc-powerful-drop-in-replace...
Yes, but it doesn't bundle and automatically compile the appropriate C library for the platform. Zig does.
The point about the Python package example is not to say that Zig can get on platforms where Rust can't, but rather that the C infrastructure that we all use is not that easy to replace and every time you touch something, regardless of how decrepit and broken it might have been, you will irritate and break someone else's use case, which can be a necessary evil sometimes but not always.
This is a point I made in the section of the blog post dedicated to explaining the limits or rewriting code.
To some extent. Rust, due to relying on LLVM, is limited by its available targets; and so cannot enjoy the full access that C/C++ can. The same is true for Zig, however, since it does not compile to C.
The author is not under any such impression. The key point is that Zig can cross-compile C/C++ code, while Rust can't. If you have a Rust project that depends on C code, you will have to put in some work if you want to compile it for a different target.
That's a pretty big difference in practice. The point about the Python package example is not to say that Zig can get on platforms where Rust can't, but rather that the C infrastructure that we all use is not that easy to replace and every time you touch something, regardless of how decrepit and broken it might have been, you will irritate and break someone else's use case, which can be a necessary evil sometimes but not always.
This is a point I made in the section of the blog post dedicated to explaining the limits or rewriting code.
> since it does not compile to C.
Give it some time, it will.
> If you have a Rust project that depends on C code, you will have to put in some work if you want to compile it for a different target.
Rust is built on LLVM, and so its toolchain can also cross-compile C/C++ code. There are crates for that[0], and projects inspired by that idea[1].
> Give it some time, it will.
Given enough time mountains become valleys. Zig doesn't compile to C now; and won't be mature and field-tested for a decade or more.
"This crate calls out to the most relevant compiler for a platform, for example using cl on MSVC."
So if you can't use Rust because it doesn't have the broad compiler support that C does, you almost certainly can't use Zig either for the exact same reason. And then the article touts Zig using their own in-house linker, which seems inevitable to have less platform support than LLVM will? Zig isn't wrong for doing that, but you can't claim that's a benefit at the same time the problem with Rust is it's lack of fringe system support... :/
ZLD can link for M1 while LLVM can't yet. And Zig can also use lld alongside it to increase the platform coverage.
> but you can't claim that's a benefit at the same time the problem with Rust is it's lack of fringe system support... :/
I find it hard to believe that a dispassionate reader could misinterpret to this degree the goal of a sentence written in a chapter dedicated entirely to showcase the limits of rewriting code in another language, be it RIIR or RIIZ.
See my reply to the parent comment for the intended meaning of that example.
Is this a matter of popularity or features ?
With that said, I've heard the situation has improved since then.
For example, one of the biggest claims has always been fast compilation. Here's V compiling itself in 0.3 seconds: https://www.youtube.com/watch?v=pvP6wmcl_Sc
V was also self hosted (written in V) from the start, which says a lot about the maturity of the language.
> Combined with all the delays
There were no delays. The project was announced to be released in June, and it was.
By the way, we now have a cool OS written in V, that can already run Bash, g++, and V itself!
How could that possibly be true? You need a V compiler to compile V but none would have existed "from the start".
You've also said multiple times on Discord that the original V compiler was written in Go.
On home page, the very first claim:
> No null
However V has `nil` or any reference can be initialized to `0`. How is then claiming `no null` not false?
I like Kristoff from what I've read of him. He seems like a leader who will take responsibility and not shy away from hard decisions.
On that quality alone, my money is on Zig winning systems programming over Rust in 10 years.
Rust also has good C FFI story and honestly I think we will still see a lot of important code rewritten in Rust.
That said, a more ergonomic C which seamlessly replaces the often bloated build configuration of C/C++ projects while allowing a far nicer language to slowly replace the existing code feels like TypeScript for JS (which I consider a good and smart thing). Definitely agree it's going to get far more use than I'd originally have guessed.
[0]: https://adventures.michaelfbryan.com/posts/how-to-riir/
Furthermore, LLD doesn't support incremental compilation. It's just not fast enough for our compilation performance goals.
There are also known techniques like Type-After-Type that can avoid use-after free in C and C++ [0]. And also advances in hardware like ARM MTE [1]. Those things - and GPA, and not reusing 64-bit pages - have various tradeoffs in terms of overhead, but Zig is a developing language that has a chance to explore possibilities that C and C++ can't. So this is an interesting area to follow.
[0] https://dl.acm.org/doi/10.1145/3274694.3274705 [1] https://security.googleblog.com/2019/08/adopting-arm-memory-...
Seriously. You get these tests for free with zig, no extra tooling, if you use testing allocator in your tests. This also is a carrot to get you to write tests. Hell, I even mocked libc's malloc/calloc/free to make sure that my code doesn't leak memory:
https://github.com/ityonemo/Primes/blob/ee81d05e80d68854ab11...