4 ms·
> No, Zig is simply not memory safe. I didn't claim that it is. I said it has a good memory safety story, i.e. mechanisms that soundly guarantee some kinds of
by pron 4y ago
> No, Zig is simply not memory safe.
I didn't claim that it is. I said it has a good memory safety story, i.e. mechanisms that soundly guarantee some kinds of memory safety, plus a design that helps write correct programs. Correctness in general, and memory safety in particular, are very central concerns in Zig's design, it's just that its story isn't one of sound guarantees across the board but, rather, some balanced mix of approaches -- some based on soundness, others based on facilitating comprehension and easier testing.
> Most software in 2022 is written in languages that are memory safe. Zig is quite the outlier here.
No, Zig is a low-level language, and the vast majority of low-level programs in 2022 are written in languages whose memory-safety story is worse than Zig's.
> This says nothing about whether a brand-new language should be memory safe.
That's right. We don't yet have an answer to that question, because we don't yet have sufficient experience with low-level languages that do have sound memory safety guarantees. I mean, it sure is better to have more guarantees if they come for free, but there's no such option in front of us just yet.
> No, there actually is PL consensus that all new languages should be memory-safe
No, there really isn't one when it comes to low-level languages (and the interest in Zig is proof that there is no consensus that it shouldn't exist). Rust is a low level language with sound memory safety guarantees, which comes at a price that makes it unappealing for some, and so various other approaches are being tried as well.
You can't insist there's consensus when clearly there are people who disagree with you. That's the definition of a lack of consensus. I also think it is premature, to say the least, to declare an approach that is currently still far from proving a success as the only way.
- pcwalton 4y ago> I didn't claim that it is. I said it has a good memory safety story, i.e. mechanisms that soundly guarantee some kinds of memory safety, as well as a design that makes it relatively easy to help write correct programs. Zig doesn't have mechanisms that soundly guarantee some kinds of memory safety. It's not spacially memory safe: extern unions, sentinel-terminated pointers, and multi-element pointers break it. At best, we think there's probably some subset of Zig that you could define that is spacially memory safe. (This isn't a particularly interesting property because it's trivially true for any language, by the way: C without pointers and without arrays is a subset of C that's memory safe, for instance, and also uninteresting.) > No, Zig is a low-level language, and the vast majority of low-level programs in 2022 are written in languages whose memory-safety story is worse than Zig's. Zig claims to be a general-purpose language, not just a low-level one. From [1]: "Zig is a general-purpose programming language and toolchain for maintaining robust, optimal, and reusable software." > I mean, it sure is better to have more guarantees if they come for free, but there's no such option in front of us just yet. It's better to have more guarantees if the benefit of the guarantees outweighs the cost, not if there is no cost. For example, for many apps, the benefit of memory safety outweighs the cost of a garbage collector. > You can't insist there's consensus when clearly there are people who disagree with you. That's the definition of a lack of consensus. Consensus doesn't mean that nobody disagrees. It means that the opposite position is a fringe view. [1]: https://ziglang.org/documentation/master/ https://ziglang.org/documentation/master/
- pron 4y ago> Zig doesn't have mechanisms that soundly guarantee some kinds of memory safety. It does. > It's not spacially memory safe: extern unions, sentinel-terminated pointers, and multi-element pointers break it. We've been through that. Those are syntactically delineated unsafe features for C/hardware interop. Rust has them, too. > This isn't a particularly interesting property because it's trivially true for any language That's right, but Zig is much closer to Rust than to C in that regard. It has clearly marked unsafe features for C or hardware interop, which aren't used in other situations and could be mechanically excluded -- just as in Rust. > Zig claims to be a general-purpose language, not just a low-level one. Surely you agree it's also a low-level language? > It's better to have more guarantees if the benefit of the guarantees outweighs the cost, not if there is no cost. Yep, and we don't know if we're there in low level languages. So far it seems that some people find the cost of Rust acceptable and others do not. In other words, there's no consensus on what the acceptable cost is. > It means that the opposite position is a fringe view. So disagreeing that the only right design is that of a language that's struggling to get 1% of the market is a fringe view? That's like a Haskeller declaring that it is a fringe view to disagree that non-strict pure functional programming is the only right way to write programs. I think that Odin and JAI, two other low level languages in development, also don't go down the full memory-safety soundness path. Seems to me to be quite far from a fringe view. If people aren't buying what Rust is selling -- regardless of how strongly some feel about the justice of its approach -- I think that those of us who care about correctness must explore alternatives, and Zig is certainly a fascinating alternative. It might well be the case that neither Rust nor Zig succeed in the market, but even in that case, both can certainly serve as inspiration for the languages that follow.
- pcwalton 4y ago> We've been through that. Those are syntactically delineated unsafe features for C interop. Rust has them, too. And again we're assuming that the ones we went over in the previous thread are all there is. I found some more: @intToPtr, @bitCast, @alignCast. Some of those @ functions are spatially-memory-safe, and some are not: the differences are not clearly called out. (I'm going to charitably assume that taking a pointer to an element in a dynamically-allocated array, and then shortening that array and dereferencing that pointer, is a temporal memory safety violation rather than a spatial one.) > That's right, but Zig is much closer to Rust than to C in that regard. It has clearly marked unsafe features for C interop. How are they clearly marked, when they're neither relegated to a separate section of the documentation nor behind a switch? As far as I can tell, the person who has gone through the most effort to isolate the spatial memory safe subset of Zig is me, in these HN threads. > So disagreeing that the design of a language that's struggling to get 1% of the market is the only right way is a fringe view now? Again, "struggling to get 1% of the market" is a weird way to describe a language that's serving billions of users right now.