Systems Programming with Zig

(manning.com)

148 points | by signa11 3 days ago ago

84 comments

  • materiallie 5 hours ago

    Zig certainly has a lot of interesting features and good ideas, but I honestly don't see the point of starting a major project with it. With alternatives like Rust and Swift, memory safety is simply table stakes these days.

    Yes, I know Zig does a lot of things to help the programmer avoid mistakes. But the last time I looked, it was still possible to make mistakes.

    The only time I would pick something like C, C++, or Rust is if I am planning to build a multi-million line, performance sensitive project. In which case, I want total memory safety. For most "good enough" use cases, garbage collectors work fine and I wouldn't bother with a system's programming language at all.

    That leaves me a little bit confused about the value proposition of Zig. I suppose it's a "better C". But like I said, for serious industry projects starting in 2025, memory safety is just tablestakes these days.

    This isn't meant to be a criticism of Zig or all of the hard work put into the language. I'm all for interesting projects. And certainly there are a lot of interesting ideas in Zig. I'm just not going to use them until they're present in a memory safe language.

    I am actually a bit surprised by the popularity of Zig on this website, given the strong dislike towards Go. From my perspective, both languages are very similar, from the perspective that they decided to "unsolve already solved problems". Meaning, we know how to guarantee memory safety. Multiple programming languages have implemented this in a variety of ways. Why would I use a new language that takes a problem a language like Rust, Java, or Swift already solved for me, and takes away features (memory safety) that I already have?

    • scuff3d 15 minutes ago

      > ...memory safety is simply table stakes these days.

      Is there like a mailing list Rust folks are on where they send out talking points every few months? I have never seen a community so in sync on how to talk about a language or project. Every few months there's some new phrase or talking point I see all over the place, often repeated verbatim. This is just the most recent one.

    • dustbunny 4 hours ago

      > memory safety is simply table stakes

      Why?

      And also, this is black and white thinking, implying that "swift and rust" are completely memory "safe" and zig is completely "unsafe". It's a spectrum.

      The real underlying comparison statement here is far more subjective. It's along the lines of: "I find it easier to write solid code in rust than in zig". This is a more accurate and fair way to state the semantics of what you are saying.

      Saying things like "rust is memory safe. Zig is not memory safe" is reductionist and too absolutist.

      • Barrin92 4 hours ago

        >Why?

        Memory bugs are hard to debug, potentially catastrophic (particularly concerning security) and in large systems software tend to constitute the majority of issues.[1]

        It is true that Rust is not absolutely memory safe and Zig provides some more features than C but directionally it is correct that Rust (or languages with a similar design philosophy) eliminate billion dollar mistakes. And you can take that literally rather than metaphorically. We live in a world where vulnerable software can take a country's infrastructure out.

        [1] https://www.zdnet.com/article/microsoft-70-percent-of-all-se...

      • DarkNova6 2 hours ago

        If decades of experience shows us anything it is that discipline and skill is not enough to achieve memory safety.

        Developers simply aren’t as good at dealing with these problems as they think they are. And even if a few infallible individuals would be truly flawless, their co-workers just aren’t.

    • winrid 5 hours ago

      Zig has a pretty great type system, and sometimes languages like Rust and C++ are not great with preventing accidental heap allocations. Zig and C make this very explicit, and it's great to be able to handle allocation failures in robust software.

      • pjmlp 5 hours ago

        That is the usual fallacy, because it assumes everyone has full access to whole source code and is tracking down all the places where heap is being used.

        It also assumes that the OS doesn't lie to the application when allocations fail.

        • simjnd 3 hours ago

          Zig make allocations extremely explicit (even more than C) by having you pass around the allocator to every function that allocates to the heap. Even third-party libraries will only use the allocator you provide them. It's not a fallacy, you're in total control.

          • pjmlp 2 hours ago

            Why, are you going to abort if too many calls to the allocator take place?

            • simjnd 2 hours ago

              You can if you want. You can write your own allocator that never actually touches the heap and just distributes memory from a big chunk on the stack if you want to. The point is you have fine grained (per function) control over the allocation strategy not only in your codebase but also your dependencies.

              • pjmlp 2 hours ago

                Allocation strategy isn't the same as knowing exactly exactly when allocations take place.

                You missed the point that libraries can have their own allocators and don't expose customisation points.

        • renehsz 3 hours ago

          > It also assumes that the OS doesn't lie to the application when allocations fail.

          Gotta do the good ol'

            echo 2 >/proc/sys/vm/overcommit_memory
          
          and maybe adjust overcommit_ratio as well to make sure the memory you allocated is actually available.
          • pjmlp 2 hours ago

            OS specific hack and unrelated to C.

            • tredre3 an hour ago

              Your comment was also OS-specific because Windows doesn't lie to applications about failed allocations.

    • osigurdson 3 hours ago

      >> Why would I use a new language...

      If you are asking that question you should not use a new language. Stick with what works for you. You need to feel that something is unsatisfactory with what you are using now in order to consider changing.

    • jmull 3 hours ago

      To me the argument is that memory errors are just one type of logic error that can lead to serious bugs. You want a language that reduces logic errors generally, not just memory safety ones, and zig's focus on simplicity and being explicit might be the way to accomplish that.

      For large performant systems, what makes sense to me is memory safety by default, with robust, fine-grained levers available to opt in to performance over safety (or to achieve both at once, where that's possible).

      Zig isn't that, but it's at least an open question to me. It has some strong safe-by-default constructs yet also has wide open safety holes. It does have those fine-grained levers, plus simplicity and explicitness, so not that far away. Perhaps they'll get there by 1.0?

      • DarkNova6 2 hours ago

        Logical errors and Memory errors aren’t even close to being in the same ballpark.

        Memories errors are deterministic errors with non-deterministic consequences. Logical errors are mostly non-deterministic (subjective and domain dependent) but with deterministic consequences.

    • pron 4 hours ago

      Yes, we know how to offer memory safety; we just don't know how to offer it without exacting a price that, in some situations, may not be worth it. Memory safety always has cost.

      Rust exists because the cost of safety, offered in other languages, is sometimes too high to pay, and likewise, the cost Rust exacts for its memory safety is sometimes too high to pay (and may even adversely affect correctness).

      I completely agree with you that we reach for low-level languages like C, C++, Rust, or Zig, in "special" circumstances - those that, for various reasons, require precise control over hardware resource, and or focuses more on the worst case rather than average case - and most software has increasingly been written in high-level languages (and there's no reversal in this trend). But just as different factors may affect your decisions on whether to use a low-level language, different factors may affect your decision on which low-level language to choose (many of those factors may be subjective, and some are extrinsic to the language's design). Of course, if, like the vast majority of programmers, you don't do low-level programming, then none of these languages are for you.

      As a long-time low-level programmer, I can tell you that all of these low-level languages suffer from very serious problems, but they suffer from different problems and require making different tradeoffs. Different projects and different people may reasonably want different tradeoffs, and just as we don't have one high-level language that all programmers like, we also don't have one low-level language that all programmers like. However, preferences are not necessarily evenly distributed, and so some languages, or language-design approaches, end up more popular than others. Which languages or approaches end up more popular in the low-level space remains to be seen.

      Memory safety is clearly not "table stakes" for new software written in a low level language for the simple reason that most new software written in low level languages uses languages with significantly less memory safety than Zig offers (Zig offers spatial memory safety, but not temporal memory safety; C and C++ offer neither, and most new low level software written in 2025 is written in C or C++).

      I can't see a strong similarity between Go, a high-level language, and Zig, a low-level language, other than that both - each in its own separate domain - values language simplicity. Also, I don't see Zig as being "a better C", because Zig is as different (or as similar) from C as it is from C++ or Rust, albeit on different axes. I find Zig so different from any existing language that it's hard to compare it to anything. As far as I know, it is the first "industry language" that's designed almost entirely around the concept of partial evaluation.

      • hawk_ 8 minutes ago

        Would you say writing something like a database (storage and query engine) from scratch is better done in Rust or Zig?

    • SvenL 4 hours ago

      Since most system level api provide a C interface and the c interoperability of zig is top notch you don’t require a marshaling/interop layer.

      • bigstrat2003 4 hours ago

        That's true of Rust as well, so it's not really an advantage unique to Zig.

    • sparky4pro 27 minutes ago

      Tried to use Swift outside Xcode and it’s a pain. Especially when writing CLI apps the Swift compiler chocked and says there is an error, mentioning no line number. Good luck with that. Also the Swift tooling outside Xcode is miserable. Even Rust tooling is better than that, and Swift has a multi billion dollar company behind it. What a shame…

    • tliltocatl 2 hours ago

      None of all those memory-safe languages allows you to work without a heap. And I don't mean "avoid allocations in that little critical loop". I mean "no dynamic allocation, never ever". A lot of tasks doesn't actually require dynamic allocation, for some it's highly undesirable (e. g. embedded with limited memory and long uptimes), for some it's not even an option (like when you are writing an allocator). Rust has some support for zero-runtime, but a lot of it's features is either useless of outright in the way when you are not using a heap. Swift and others don't even bother.

      Unpopular opinion: safety is a red herring. A language shouldn't prevent the programmer from doing the unsafe thing, rather it should provide an ergonomic way to do things in a safe way. If there is no such way - that's on language designer, not the programmer. Rust being the worst offender: there is still no way to do parent links, other than ECS/"data oriented" which, while it has it's advantages, is both quite unergonomic and provides memory safety by flaying it, stuffing the skin with cow dung and throwing the rest out of the window.

      >strong dislike towards Go.

      Go unsolves problem without unlocking any new possibilities. Zig unsolves problem before it aims towards niches where the "solution" doesn't work.

      • needlesslygrim 2 hours ago

        > Rust has some support for zero-runtime, but a lot of it's features is either useless of outright in the way when you are not using a heap.

        Could you give some examples?

    • apwell23 4 hours ago

      rust has really high learning curve

      • osigurdson 3 hours ago

        Perhaps worse is the fatigue curve that some people claim sets in after a few years of using it.

        • hitekker 3 hours ago

          Do you have links on people’s experience with the fatigue curve?

          I’ve heard of “hard to learn, easy to forget” but I haven’t seen people document it for career reasons.

          • osigurdson an hour ago

            I have no hard data. I have seen comments to this effect in HN. Somewhat famously Primagen threw in the towel on it. I would love to hear from others with 4+ years of Rust experience though.

          • hu3 2 hours ago

            I guess lack of job positions could be one kind of fatigue curve.

    • xwowsersx 4 hours ago

      Genuinely curious because I don't know: when you group Swift with Rust here, do you mean in terms of memory safety guarantees or in the sense of being used for systems-level projects? I've always thought of Swift as having runtime safety (via ARC), not the same compile-time model as Rust, and mostly confined to Apple platforms.

      I'm surprised to see them mentioned alongside each other, but I may very well be missing something basic.

  • gabrielgio 3 days ago

    As a developer interested in zig it is nice to see books being release, but I'd be a bit resitant to buy anything before zig reaches 1.0 or at least when they settle on a stable api. Both the builder and the std keep changing. Just 0.15 is a huge breakage. Does anyone knows how those changes would affect this book?

    • osigurdson 8 hours ago

      People are doing real companies with Zig (e.g. Tiger Beetle) and important projects (e.g. Ghostty) without the 1.0 backward compatibility guarantee. Zig must be doing something right. Maybe this also keeps opinionated 9-5er, enterprise type devs out of it as well which might be a good thing :).

      • Rochus 7 hours ago

        Are there other notable commercial companies/projects than Tiger Beetle relying on Zig? According to public information, Tiger Beetle are about eight employees with a single customer, isn't it?

        • hawk_ 6 minutes ago

          Who is that single customer? I'd have thought by now there would be more.

        • jakogut 7 hours ago

          Bun.sh uses zig for large portions of native code.

          • Rochus 7 hours ago

            Thanks for the hint. According to public sources, Bun's runtime infrastructure and bindings are written in Zig, but it uses Apple's JavaScriptCore engine written in C++ (i.e. Zig is essentially used in a thin wrapper layer around a large C++ engine). Bun itself apparently struggles with stability and production readiness. Oven (Bun's company) has around 2-10 employees according to LinkedIn.

        • throwawaymaths 6 hours ago

          lightpanda and bun

          • Rochus 6 hours ago

            Lightpanda looks interesting, thanks for the hint. According to public sources, behind the development is a company of 2-10 employees (like Bun). The engine uses parts of the Netsurf browser (written in C) and the V8 engine (written in C++), and - as far a I can tell - is in an early development stage.

      • wolvesechoes 3 hours ago

        I guess almost every single language out there have at least one "real" company using it, so yeah, Zig is still mostly hype and blog post praising its awesomeness.

        • hu3 2 hours ago

          I disagree, since there's Bun also to exemplify real, popular, tools are being created.

          https://bun.com

    • Rochus 13 hours ago

      Is this really the first Zig book since the development startet in 2016? Maybe the language and library is just too volatile for a book.

      • wslh 5 hours ago

        Or it evolves smoothly at another pace.

    • justinhj 4 hours ago

      As a Zig adopter I was rooting for this because even though there is the official documentation and some great community content, it's nice to just kick back and read a well written book. I'm also very happy with other Manning titles; they have built a high level of trust with me.

      To answer your question is it too early. My expectation is that the core language, being quite small by design, will not change that much before 1.0. Some things will, especially async support.

      What I think we will see is something like a comprehensive book on C++14 . The language is not much changed between now and then, but there will be new sections to add and some sections to rework with changes to the interface. The book would still be useful today.

      Not a perfect analogy because C++ maintains backwards compatibility but I think it is close.

    • turtleyacht 3 days ago

      Author links to 0.15.1 Zig docs in several places, at least for now.

      Outstanding issue on Zig side for 1.0 release: https://github.com/ziglang/zig/issues/16270

    • zwnow 13 hours ago

      With how its going I feel Zig 1.0 wont be a thing until my retirement in 37 years

      • testdelacc1 12 hours ago

        I’m willing to bet $5 it happens in 4 years or fewer.

        • ebri 12 hours ago

          That’s a pretty low confidence if we measure confidence in dollars willing to risk

          • testdelacc1 11 hours ago

            It’s 100% of my annual betting budget though!

        • noshitsherlock 3 hours ago

          Wouldn’t you think AI advances in 4 years would make this a safe bet?

          • therein 2 hours ago

            No, unless you're riding the hype train so hard that you are excited to go to colonize Mars thanks to AI advances.

        • tialaramex 8 hours ago

          Do you have a history we can look at to see how good you are at predicting this for programming languages? Like say, some 2020 predictions you had for languages which would or would not ship 1.0 by 2025 ?

          • testdelacc1 4 hours ago

            I made a set of predictions for Rust in 2022, nearly all of which turned out to be correct. And I was publicly confident Go and Rust would be massive when they reached 1.0. I was right on both counts.

            But I will also admit I don’t follow developments in zig as closely as Rust. I’ve never written any Zig. And in any case, past performance isn’t indicative of future performance.

            I could be wrong about this prediction, but I don’t think I will be. From what I’ve seen Andy Kelley is a perfectionist who could work on point releases forever. But his biggest users (tigerbeetle and bun especially) will only be taken seriously once Zig is 1.0. They’ll nudge him towards 1.0. They can wait a few years, but not forever. That’s why I guessed 4 years.

            • jorangreef 4 hours ago

              > But his biggest users (tigerbeetle and bun especially) will only be taken seriously once Zig is 1.0.

              TB is only 5 years old but already migrating some of the largest brokerages, exchanges and wealth managements in their respective jurisdictions.

              Zig’s quality for us here holds up under some pretty extreme fuzzing (a fleet of 1000 dedicated CPU cores), Deterministic Simulation Testing and Jepsen auditing (TB did 4x the typical audit engagement duration), and is orthogonal to 1.0 backwards compatibility.

              Zig version upgrades for our team are no big deal, compared to the difficulty of the consensus and local storage engine challenges we work on, and we vendor most of our std lib usage in stdx.

              > They’ll nudge him towards 1.0.

              On the contrary, we want Andrew to take his time and get it right on the big decisions, because the half life of these projects can be decades.

              We’re in no rush. For example, TigerBeetle is designed to power the next 30 years of transaction processing and Zig’s trajectory here is what’s important.

              That said, Zig and Zig’s toolchain today, is already better, at least for our purposes, than anything else we considered using.

  • picafrost 11 hours ago

    Excellent way to stay busy producing revised editions over the next few years.

    I really enjoy writing Zig and I think it's going to be an important language in the future. I do not enjoy porting my code between versions of the language. But early adopters are important for exploring the problem space, and I would have loved to find a canonical source (aside from the docs, which are mostly nice) for learning the language when I did. A text that evolves with the language has a better chance of becoming that canonical onboarding source.

  • techjuice 8 hours ago

    I think this is great, gives those wanting a good formal foundation a guide to getting organized and making something happen.

    With time this is also going to be great for the author with new iterations of the book, but getting in early like this can set the author and the language up for success long term.

  • bjackman 11 hours ago

    Not a comment on the book but I hope a slightly off topic thread is OK...

    As a systems programmer, what is the selling point of Zig? For me, memory safety is the number 1, 2, 3, 4 and 5 problem with C. A new language that doesn't solve those problems seems very strange to me. And as a counterpoint, I will tolerate massive number of issues with Rust because it gives us memory safety.

    I work in security so that may give me a bias. But maybe instead of "bias" it's more like awareness. If you don't deal with it day in, day out, it seems impossible to really internalise how completely fucking broken something like the Linux kernel is. Continuing to write e.g. driver code in an unsafe language is just not acceptable for our civilisation.

    But, also maybe you don't need full complete memory safety, if a language has well designed abstractions maybe it can just be "safe enough in practice". I've worked on C++ code that feels that way. Is this the deal with Zig?

    • pron 10 hours ago

      1. Lack of memory safety is a big problem particularly because it's a common cause of dangerous vulnerabilities, but spatial safety is more important than temporal safety for that reason, and Zig does offer spatial safety.

      2. Other important issues of concern when it comes to security/correctness are language complexity and compilation speed. A complicated language with lots of implicitness can obscure bugs and make reviews slower. Slow compilation reduces the iteration speed and harms testing. Zig focuses on these two. The language is simple, with no implicitness - overloading of any kind is not allowed and neither are any kind of hidden calls. Even if security were the only concern, it's not clear at all how much complexity and compilation speed should be sacrificed for temporal safety. Remember that it's easy to classify bugs by technical causes, but more diffuse aspects, like testing and review, are also very important, and Zig tries to find a good balance.

      3. Nevertheless, the language is still very expressive [1]. In any language, you want the algorithm to be clear and with neither extraneous nor important hidden details for that domain. I think Zig gets that about right for low-level programming (and C++ doesn't).

      For me, the #1 problem with C is lack of safety and the #2 problem is lack of expressivity. With C++, the main problem for me is language complexity and implicitness, with slow compilation and lack of safety tied for number 2. So Zig is as expressive as C++. but not only safer, but also much simpler, and compiles faster (and improving compilation speed further is an important goal).

      [1]: I say that two languages are equally expressive if, over all algorithms, idiomatic implementations in both languages (that are roughly equally clear) differ in length by no more than a linear relation with a small constant.

      • pRusya 3 hours ago

        > So Zig is as expressive as C++. but not only safer, but also much simpler, and compiles faster

        Tbh syntax-wise Zig feels more cryptic[1] at first than C++.

        [1] e.g. `extern "user32" fn MessageBoxA(?win.HWND, [*:0]const u8, [*:0]const u8, u32) callconv(win.WINAPI) i32;` from https://ziglang.org/learn/samples/

        • tredre3 an hour ago

          To be clear the equivalent C++ code is:

              #include <windows.h>
              extern "C" __declspec(dllimport) int __stdcall MessageBoxA(HWND, LPCSTR, LPCSTR, UINT);
              // or
              extern "C" __declspec(dllimport) int __stdcall MessageBoxA(void *, const char[], const char[], unsigned int);
          
          It's not exactly a stellar improvement.
          • npalli an hour ago

            Lol, no this is the equivalent

              #include <windows.h>
            
             int main() {
                  MessageBoxA(NULL, "world!", "Hello", 0);
                  return 0;
              }
        • pron 3 hours ago

          I think that's just a matter of syntax habits, presumably because you're already familiar with C++ syntax. The syntax in your example is especially "cryptic" simply because it's an FFI signature (of a function that's not written in Zig and doesn't use the normal Zig data representations).

      • mi_lk 5 hours ago

        Can you say more about spatial security v.s. temporal security and how Zig does them?

        • pron 4 hours ago

          Spatial memory safety means that a language (at least in its subset that's designated "safe") doesn't allow you to manufacture pointers into memory that may contain data of a different type than what's expected by the pointer (we'll call such pointers "invalid"). The classic examples of spatial memory safety is guaranteeing that arrays are never accessed out of bounds (hence "spatial", as in pointers are safely constrained in the address space). Zig guarantees (except when using delineated "unsafe" code) such spatial safety.

          Temporal memory safety is the guarantee that you never access pointers that have been valid at some point in time after they've become invalid due to reallocation of memory; we call such pointers "dangling" (hence "temporal", as in pointers are safely constrained in time). The classic example of this is use-after-free. Zig does not guarantee temporal safety, and you can accidentally have a dangling pointer (i.e. access a one-time valid pointer after it's become invalid).

          Invalid pointers are especially dangerous because, in languages where they can occur, they've been a very common source of exploitable security vulnerabilities. However, violating spatial memory bounds is more dangerous, as the result is more easily exploited by attackers in the case of a vulnerability, as it's more predictable.

    • throwawaymaths 6 hours ago

      1. you get spatial memory safety which iirc is more common for security problems than temporal.

      2. honestly for high performance applications you might reach for an ECS type system anyways (i think dom engines do this) at which point you would be getting around the borrow checker anyways.

    • ptrwis 6 hours ago

      Maybe in the future, if the language has very good AI support, security guarantees of the language won't be as important, as it (ai) will find potential bugs well enough. This may be the case with Zig, as the language is simple and consistent, and the lack of macros will make it easier for LLMs to understand the code.

      • bigstrat2003 4 hours ago

        AI is not remotely capable enough to be trusted with that. Perhaps in the future it will be, but I'm not betting on it with the lack of improvement we have seen thus far.

    • hansvm 8 hours ago

      You touched on the idea in your last paragraph. Comparing Zig to C using memory safety as a binary threshold instead of a continuous scale is apples to oranges.

      For one, Rust isn't even at the far right of the memory safety scale, so any argument against Zig due to some epsilon of safety has to reckon with the epsilon Rust is missing as well. That scale exists, and in choosing a language we're choosing (among other things) where on that scale we want to be. Maybe Rust is "good enough", and maybe not.

      For two, there's a lot more to software design than memory safety _even when your goals revolve around the safety and stability of the end product_.

      So long as you get the basics right (like how Zig uses slices by default and has defer/errdefer statements), you won't have an RCE from a memory safety bug, or at least not one that you wouldn't likely see in Rust anyway (e.g., suppose you're writing a new data structure in both languages; suppose that it involves back-references or something else where the common pattern in Rust would involve creating backing memory and passing indices around, combined with an unsafe block on the actual cell access to satisfy the borrow checker; the fact that you had to do something in an unsafe block opens you up to safety issues like index wraparound causing OOB reads).

      If memory safety is "good enough" from an RCE perspective, what are we buying with the rest of Rust's memory safety? Why is it so important? For everything else, you're just preventing normal application bugs -- leaking user data, incorrect computations, random crashes, etc. The importance of normal application bugs varies from project to project, but in the context of systems programming of any kind I'll argue that these are absolutely as critical as RCEs and the other "big" things you're trying to prevent via memory safety. The whole reason you try to prevent an RCE is to ensure that you have access to your files/data/tools and that an attacker doesn't, but if logic bugs corrupt data, crash your tools, and leak PII then you're still fucked. Memory safety didn't save you.

      That shift in perspective is important. If our goal is preventing ordinary application bugs on top of memory-safety bugs it becomes blatantly obvious that you'd be willing to trade a little safety for some bug prevention.

      Does Zig actually help reduce bugs though? IME, yes. The big thing it has going for it is that it's a small, cohesive language that gives you the power you need to do the things you're trying to do. Being small makes it possible to create features that compose well and are correct by default, and having the power to do what you're trying to do means you don't have to create convoluted (expensive, bug-prone) workarounds. Some examples:

      1. `let` rebindings in Rust are a great feature, and I like them a lot. Better than 90% of the time I use them correctly. The other 10% I'm instead trying to create a new variable and accidentally shadowing an existing one. That's often not the end of the world, but if there exists any code after my `let` rebinding expecting the old value then it's totally incorrect (assuming compatible types so that you don't have a compilation failure). Zig yells loudly about the error.

      2. The error-handling system in Zig is easy to get right because of largely compatible return types. By contrast, I see an awful lot of `unwrap` in Rust code in places that really shouldn't have it, and in codebases that try to use `?` or other more-likely-to-be-correct strategies the largely incompatible return types force most people into slapping `anyhow` around everything and calling it a day.

      3. Going back to error-handling, Rust allows intentional discards of return values, but if you start by discarding the return value of a non-error function and the signature is later updated to potentially return errors Rust still lets you discard the value. Zig forces you to do something explicitly acknowledging that there was an error. 100% of the time the compiler has yelled at me for a potential logic bug it was correct to do so.

      It really is just a bunch of little things, but those little things add up and make for a pleasant language with shockingly few bugs. Maybe my team is just even more exceptional than I already think or something and I'm over-indexing on the language, but in the last couple years I haven't seen a single memory safety issue, or much in the way of other bugs in the Zig part of the company.

      • tialaramex 6 hours ago

        1. I guess by "let rebinding" you mean shadowing. Clippy has lints for shadowing which are default off, you might find that some patterns of shadowing which are legal in Rust are too often problematic in your software and so you should tell Clippy to warn you about them or even deny them by default.

        For example you might decide to warn for clippy::shadow_unrelated which says if I have a variable named "goose" and then later in the function I just make another variable that's not obviously derived from the first variable but it is called "goose" anyway, warn me I did that.

        2. I don't see any advantage of "largely compatible" error handling over anyhow, maybe you could be more explicit about what you want here or give an example.

        3. What you're claiming for Zig here is a semantic check. This could exist but be fallible (it can't be infallible because Rice's Theorem), but I suspect the reality is that it's not a semantic check and you've misattributed your experience since I don't see any such check in Zig. Maybe an example would clarify.

        • hansvm 2 hours ago

          I really didn't mean to make this about Zig vs Rust. That was a mistake. My real point is that Zig is also a great language, even when you care about safety.

          That said, the things you asked about:

          1. I suppose you might get away with linting all of shadow_reuse, shadow_same, and shadow_unrelated. Would that sufficiently disable the feature?

          2. The biggest problems with overusing `anyhow` to circumvent the language's error system are performance and type safety. Perf is probably fine enough for most applications (though, we _are_ talking about systems programming, and this is yet another way in which allocation-free Rust is hard to actually do), but not being able to match on the returned error makes appropriately handling errors clunkier than it should be, leading to devs instead bubbling things up the call stack even more than normal or "handling" the error by ignoring any context and using some cudgel like killing connections regardless of what the underlying error was.

          3. Rice's Theorem is only tangentially related. Your goal, and one that Rust also strives for, is to make it so that changes to the type signature of a function require compatible changes at call sites, which you can often handle syntactically. Rust allows `let _ = foo()` to also silence errors, and where Zig normally allows `_ = foo()` to silence unhandled return values it additionally requires `try`, `catch`, or `return` (or similar control flow). You have options like `_ = foo() catch {}` or `_ = foo() catch @panic("WTF")` if you really do want to silence the error, but you'll never be caught off-guard by an error being added to a function's return type.

      • throwawaymaths 6 hours ago

        the far right of the security scale is C (+ isabelle?) again (seL4)

  • Ygg2 13 hours ago

    What is the point of this book this early? Zig is in too much flux. Language is 0.x for a reason.

    Just to gauge interest?

    • sparky4pro 19 minutes ago

      Garrison Hinson-Hasty is writing a book about a programming language that is still in flux seems a little bit… hasty. Sorry, couldn’t resist…

    • adamors 11 hours ago

      Well the MEAP just started, 3 chapters are complete and the rest will follow probably next year.

      IMO it’s a bet: Zig stays stable enough and this will be _the_ Zig book for a while. Should the bet not pay off it still cements the author as an authority on the language and gets them a foot in the door.

      • mi_lk 10 hours ago

        Looks like a win-win for the author? Why would the publisher take the bet

        • mtlynch 6 hours ago

          Manning doesn't pay that much to first time authors, and it looks like it's the first book for the author, Garrison Hinson-Hasty.

          My guess is it's about $2k upfront and the author owes it back if they don't deliver.

          Teiva Harsanyi did a good writeup recently about working with Manning as a first-time author. He got $2k upfront and $2k after delivering the first 1/3rd.[0]

          [0] https://www.thecoder.cafe/p/100-go-mistakes

          • rtfeldman 5 hours ago

            When I wrote Elm in Action for Manning, I talked with them explicitly about the language being pre-1.0 and what would happen if there were breaking changes. The short answer was that it was something they dealt with all the time; if there were small changes, we could issue errata online, and if there were sufficiently large changes, we could do a second edition.

            I did get an advance but I don't remember a clause about having to return any of it if I didn't earn it out. (I did earn it out, but I don't remember any expectation that I'd have to give them money back if I hadn't.) Also my memory was that it was more than $2k but it was about 10 years ago so I might be misremembering!

        • cultofmetatron 6 hours ago

          I bought a copy through my subscription.

          having read through a few of their books, Manning has a pretty good record of producing a lot of good content. nostarch an pragprog are arguably better in terms of writing quality (slightly) but they dont' publish nearly as many books.

          Pakt certainly has more books but the quality is absolute garbage.

          whenever a new language comes out, I usually take a weekend to at least dabble in it to see if its worth getting into. Most of the languages end up in my "cool story" bucket but its also how I found elixir and I've been working in it fulltime for the last 7 years every since.

          In the case of manning, they presell the pdf. that costs them nothing while expanding their catalog in a way that doesnt feel like a ripoff for the subscribers. I'm not expecting a MEAP title to have the same level of polish as a completed book. Rather, I appreciate having close to bleeding age info thats been somewhat curated for my consumption.

        • bombcar 9 hours ago

          Manning does this all the time, I presume the cost-to-print is so low it doesn't hurt.

          • dom96 6 hours ago

            When I wrote Nim in Action[1] for Manning, it was prior to 1.0 as well. It was definitely a bit akward, but breaking changes to the stuff covered in the book was relatively minor.

            1 - https://book.picheta.me/

    • ozgrakkurt 3 hours ago

      Language doesn’t really change that much, it is mainly stdlib and build apis changing