Zig’s io.threaded is neat

(matklad.github.io)

57 points | by chilipepperhott 17 hours ago

4 comments

  • lll-o-lll 20 minutes ago
    All my days of low level stuff were in the windows world where async/cancel was supported since nt kernel days at least. Wrapping this coherently at some level of abstraction was always worth doing, although threads are just one way. Overlapped I/O let you do it all on one thread. Linux looks harder.

    Great that Zig is supporting this more “first class”; not strictly required, but looks useful.

  • two_handfuls 16 hours ago
    Oh man this finishes too early, I would want to read more!
  • phplovesong 1 hour ago
    I know syntax does not REALLY matter, but Zig is just kind of subpar syntax wise. Its really verbose and picked weirdly from what already exists. Zig code is usually hard to read because it really noicy, and has weird things not existing in other languages without merit.
    • pzittlau 1 hour ago
      I don't think that it's really subpar. It's just unusual compared to others. In and of itself it's very consistent. For instance there's `|capture|` for capturing all sort of things(errors, optionals, ...) in nearly all control flow constructs. `blk:` for naming blocks, `if`s, `switch`, and so on. Have a look at this blog post: https://matklad.github.io/2025/08/09/zigs-lovely-syntax.html
      • ulbu 1 hour ago
        |capture| hides an inconsistency that bugs me – everywhere else, assignment to a variable flows leftwards. |capture| is an unnatural rightwards assignment.

        in general, I like zig syntax, but i find that it had very little regard to how the eye moves on the page. it’s jarring at times.

      • phplovesong 1 hour ago
        I saw that article previously. Nearly all of the syntax seem to be in-house with little benefit. All the examples could just use some modern c-like thing.

        Zig has benefits, like comptime, no hidden control flow, memory mngmt, cross compilation etc. But its syntax is just a mouthfull of wats, whys and wtfs.

        I can forsee a compile to Zig languge popping up sometime soon.

    • nromiun 1 hour ago
      Of course syntax matters in any programming language. That is like saying the alphabet and grammar does not really matter in English.
      • zuzululu 13 minutes ago
        with LLMs? syntax doesn't really matter anymore exactly because of what you mentioned in your last sentence.
  • zuzululu 2 hours ago
    I'm shipping in Rust but any reason to do so in Zig ? What does it offer over Rust ? Something tangible benefit to end user or developer using ai assisted development ?
    • rahen 1 hour ago
      Use Rust if you're not writing code yourself.

      The borrow checker will catch all kinds of bugs that AI-generated code will happily compile in Zig but will blow up as UB at runtime.

      Zig's value prop is different and closer to a modern C: it fits in your head and maps fairly closely to assembly. There is no hidden control flow or hidden allocations, so you can tweak performance at a very low level. You're the pilot, not the compiler.

      Rust trades the low-level clarity for compiler-enforced safety. If you're not a code artisan or don't care about being one, then please use Rust.

      • je42 12 minutes ago
        So far claude has been fine to generated zig code. Dont have lots of issues. Tijy local models have more problems with zig, need additional instructions.

        In general, what helps is to instruct ai to use test coverage to ensure the cover all edge cases with tests.

      • solatic 1 hour ago
        > The borrow checker will catch all kinds of bugs that AI-generated code will happily compile in Zig but will blow up as UB at runtime.

        This has not been my experience; Claude does a great job of writing unit tests for the Zig code, and combined with Zig's fuzzing features and a Python-based integration testing suite, I have avoided hitting runtime UB so far. In exchange, I get much faster compile times, which are important for the agentic development loop.

      • Ygg2 12 minutes ago
        Use Rust if you want to write in a memory safe, high performance language.

        > Zig's value prop is different and closer to a modern C: it fits in your head and it maps fairly closely to assembly.

        This can't be correct for the simple reason that it has both a modern optimizing compiler (LLVM) and UB.

        A modern compiler will try to autovectorize your code, so you don't really know what the assembly will be.

        UB gives compiler license to rewrite your code however it sees fit.

      • zuzululu 23 minutes ago
        Can LLMs not write Zig code ? I'm not really understanding your explanation for why we can write other languages with LLM but not Zig here.

        > Rust trades the low-level clarity for compiler-enforced safety. If you're not a code artisan or don't care about being one, then please use Rust.

        Not really seeing the connection here. What do you mean by code artisan? Are you trying to gatekeep Zig because you think Zig is too difficult for LLMs?

      • eptcyka 1 hour ago
        > You're the pilot, not the compiler.

        This to me reads like an LLMism.

    • hiccuphippo 1 hour ago
      Zig lets you be very explicit about what you want. Zig's hello world takes 3 or 4 lines where other languages take 1. That is how much other languages make decisions for you. Some people care to make those decisions themselves.
      • zuzululu 17 minutes ago
        As does C++ and other languages. What is so special about Zig that you cannot use LLMs with it? Please provide examples.
      • applfanboysbgon 1 hour ago
        This is the weirdest basis for comparing a language I've ever seen. Zig is one line as well, `std.debug.print("Hello, world!\n", .{});`, unless you're counting defining main and its brackets as 4 lines, in which case... Rust has that too, Java is 7 lines and C# is 8 lines to import System library and define the Program class as well if you're not using top-level statements / implicit usings.

        ---

        Edit for replies complaining I used debug.print:

        Okay, `try std.io.getStdOut().writer().print("Hello, world!\n", .{});`. Still one line, more explicit with chained methods, but that still just goes to show you how arbitrary this metric is -- Zig's standard library makes you be more explicit with one function, but it doesn't make you be as explicit with another one that works essentially the same way but writes to a different stream, ergo this has nothing to do with the language's inherent explicitness but rather comparing the implementation of a single random function.

        • denismenace 54 minutes ago
          As the name suggest `std.debug.print` is a short hand for debug printing. In a CLI app for example you should use IO.
        • solatic 1 hour ago
          std.debug.print is, as its name suggests, for debug output, not for program output.

          In Zig, you create a buffered writer for the stdout file handle, write hello world to the buffer, and then flush it. It exposes what's actually happening underneath.

    • applfanboysbgon 1 hour ago
      I often use LLMs to build and modify open-source tools for personal use and Rust's compile times are disgusting, eg. Codex CLI taking over 15 minutes to recompile on my fairly high-end machine. Zig's incremental compilation optimizations are amazing, giving near-instant recompiles measured in ms instead of minutes. I would certainly classify four orders of magnitude faster compilation as a tangible benefit even if you're not writing the code by hand.