Skip to content Skip to footer
Zig; what I think after months of using it by uaksom

Zig; what I think after months of using it by uaksom

14 Comments

  • Post Author
    taurknaut
    Posted February 5, 2025 at 3:34 am

    I loved this deep-dive of zig.

    > There’s a catch, though. Unlike Rust, ErrorType is global to your whole program, and is nominally typed.

    What does "global to your whole program" mean? I'd expect types to be available to the whole compilation unit. I'm also weirded out by the fact that zig has a distinct error type. Why? Why not represent errors as normal records?

  • Post Author
    3r7j6qzi9jvnve
    Posted February 5, 2025 at 3:37 am

    (never used zig yet myself)
    For UB detection I've read zig had prime support for sanitizers, so you could run your tests with ubsan and catch UBs at this point… Assuming there are enough tests.

    As far as I'm concerned (doing half C / half rust) I'm still watching from the sidelines but I'll definitely give zig a try at some point.
    This article was insightful, thank you!

  • Post Author
    lnenad
    Posted February 5, 2025 at 3:49 am

    When did shadowing become a feature? I was under the impression it's an anti-pattern. As per the example in the article

    > const foo = Foo.init();
    > const foo2 = try foo.addFeatureA();
    > const foo3 = try foo.addFeatureB();

    It's a non issue to name vars in a descriptive way referring to the features initial_foo for example and then foo_feature_a. Or name them based on what they don't have and then name it foo. In the example he provided for Rust, vars in different scopes isn't really an example of shadowing imho and is a different concept with different utility and safety. Replacing the value of one variable constantly throughout the code could lead to unpredictable bugs.

  • Post Author
    scubbo
    Posted February 5, 2025 at 4:08 am

    Great write-up, thank you!

    I used Zig for (most of) Advent Of Code last year, and while I did get up-to-speed on it faster than I did with Rust the previous year, I think that was just Second (low-level) Language syndrome. Having experienced it, I'm glad that I did (learning how cumbersome memory management is makes me glad that every other language I've used abstracts it away!), but if I had to pick a single low-level language to focus on learning, I'd still pick Rust.

  • Post Author
    cwood-sdf
    Posted February 5, 2025 at 4:09 am

    It seems like he wants zig to be more like rust. personally, i like that zig is so simple

  • Post Author
    ethin
    Posted February 5, 2025 at 4:12 am

    No idea how much the author is experienced at Zig, but my thoughts:

    > No typeclasses / traits

    This is purposeful. Zig is not trying to be some OOP/Haskell replacement. C doesn't have traits/typeclasses either. Zig prefers explicitness over implicit hacks, and typeclasses/traits are, internally, virtual classes with a vtable pointer. Zig just exposes this to you.

    > No encapsulation

    This appears to be more a documentation issue than anything else. Zig does have significant issues in that area, but this is to be expected in a language that hasn't even hit 1.0.

    > No destructors

    Uh… What? Zig does have destructors, in a way. It's called defer and errordefer. Again, it just makes you do it explicitly and doesn't hide it from you.

    > No (unicode) strings

    People seem to want features like this a lot — some kind of string type. The problem is that there is no actual "string" type in a computer. It's just bytes. Furthermore, if you have a "Unicode string" type or just a "string" type, how do you define a character? Is it a single codepoint? Is it the number of codepoints that make up a character as per the Unicode standard (and if so, how would you even figure that out)? For example, take a multi-codepoint emoji. In pretty much every "Unicode string" library/language type I've seen, each individual codepoint is a "character". Which means that if you come across a multi-codepoint emoji, those "characters" will just be the individual codepoints that comprise the emoji, not the emoji as a whole. Zig avoids this problem by just… Not having a string type, because we don't live in the age of ASCII anymore, we live in a Unicode world. And Unicode is unsurprisingly extremely complicated. The author tries to argue that just iterating over byes leads to data corruption and such, but I would argue that having a Unicode string type, separate from all other types, designed to iterate over some nebulous "character" type, would just introduce all kinds of other problems that, I think, many would agree should NOT be the responsibility of the language. I've heard this criticism from many others who are new to zig, and although I understand the reasoning behind it, the reasoning behind just avoiding the problem entirely is also very sensible in my mind. Primarily because if Zig did have a full Unicode string and some "character" type, now it'd be on the standard library devs to not only define what a "character" is, and then we risk having something like the C++ Unicode situation where you have a char32_t type, but the standard library isn't equipped to handle that type, and then you run into "Oh this encoding is broken" and on and on and on it goes.

  • Post Author
    edflsafoiewq
    Posted February 5, 2025 at 4:17 am

    The debate between static and dynamic typing continues unceasingly. Even when the runtime values are statically typed, it's merely reprised at the type level.

  • Post Author
    SPBS
    Posted February 5, 2025 at 4:52 am

    Headers are missing IDs for URL fragments to jump to e.g. https://strongly-typed-thoughts.net/blog/zig-2025#error-hand… doesn't work

  • Post Author
    sedatk
    Posted February 5, 2025 at 5:05 am

    > The first one that comes to mind is its arbitrary-sized integers. That sounds weird at first, but yes, you can have the regular u8, u16, u32 etc., but also u3. At first it might sound like dark magic, but it makes sense with a good example that is actually a defect in Rust to me.

    You don't need Rust to support that because it can be implemented externally. For example, crates like "bitbybit" and "arbitrary-int" provide that functionality, and more:

    https://docs.rs/crate/arbitrary-int/

    https://docs.rs/crate/bitbybit/

  • Post Author
    hoelle
    Posted February 5, 2025 at 5:08 am

    > Zig does enhance on C, there is no doubt. I would rather write Zig than C. The design is better, more modern, and the language is safer. But why stop half way? Why fix some problems and ignore the most damaging ones?

    I was disappointed when Rust went 1.0. It appeared to be on a good track to dethroning C++ in the domain I work in (video games)… but they locked it a while before figuring out the ergonomics to make it workable for larger teams.

    Any language that imbues the entire set of special characters (!#*&<>[]{}(); …etc) with mystical semantic context is, imo, more interested in making its arcane practitioners feel smart rather than getting good work done.

    > I don’t think that simplicity is a good vector of reliable software.

    No, but simplicity is often a property of readable, team-scalable, popular, and productive programming languages. C, Python, Go, JavaScript…

    Solving for reliability is ultimately up to your top engineers. Rust certainly keeps the barbarians from making a mess in your ivory tower. Because you're paralyzing anyone less technical by choosing it.

    > I think my adventure with Zig stops here.

    This article is a great critique. I share some concerns about the BDFL's attitudes about input. I remain optimistic that Zig is a long way from 1.0 and am hoping that when Andrew accomplishes his shorter-term goals, maybe he'll have more brain space for addressing some feedback constructively.

  • Post Author
    grayhatter
    Posted February 5, 2025 at 5:50 am

    lol, I knew exactly who wrote this once I saw the complaint about shadowing being forbidden. The author and I were just arguing about it the other day on irc. While the author considers it an annoying language bug because it requires creating additional variable names (given refactoring was an unpalatable option). I consider it a feature.

    Said arguments have become a recurring and frustrating refrain; when rust imposes some limit or restriction on how code is written, it's a good thing. But if Zig does, it's a problem?

    The remainder of the points are quite hollow, far be it from me to complain when someone starts with a conclusion and works their way backwards into an argument… but here I'd have hoped for more content. The duck typing argument is based on minimal, or missing documentation, or the doc generator losing parts of the docs. And "comptime is probably not as interesting as it looks" the fact he calls it probably uninteresting highlights the lack of critical examination put here. comptime is an amazing feature, and enables a lot of impressive idioms that I enjoy writing.

    > I’m also fed up of the skill issue culture. If Zig requires programmers to be flawless, well, I’m probably not a good fit for the role.

    But hey, my joke was featured as the closing thought! Zig doesn't require one to be flawless. But it' also doesn't try to limit you, or box you into a narrow set of allowed operations. There is the risk that you write code that will crash. But having seen more code with unwrap() or expect() than without, I don't think that's the bar. The difference being I personally enjoy writing Zig code because zig tries to help you write code instead of preventing you from writing code. With that does come the need to learn and understand how the code works. Everything is a learnable skill; and I disagree with the author it's too hard to learn. I don't even think it's too hard for him, he's just appears unwilling…. and well he already made up his mind about which language is his favorite.

  • Post Author
    frangfarang
    Posted February 5, 2025 at 5:55 am

    [dead]

  • Post Author
    ibraheemdev
    Posted February 5, 2025 at 8:56 am

    > The message has some weird mentions in (alloc565), but the actual useful information is there: a pointer is dangling.

    The allocation ID is actually very useful for debugging. You can actually use the flags `-Zmiri-track-alloc-id=alloc565 -Zmiri-track-alloc-accesses` to track the allocation, deallocation, and any reads/writes to/from this location.

  • Post Author
    k0tran
    Posted February 5, 2025 at 9:27 am

    [dead]

Leave a comment

In the Shadows of Innovation”

© 2025 HackTech.info. All Rights Reserved.

Sign Up to Our Newsletter

Be the first to know the latest updates

Whoops, you're not connected to Mailchimp. You need to enter a valid Mailchimp API key.