Live data from Hacker News

Why is Zig so cool?

nilostolte.github.io

161–170 of 527 posts

Re: Why is Zig so cool?

#161

In my opinion the biggest issue of Zig is that it doesn't allow attaching data to error. The error can only be passed via side channel, which is inconvenient and ENOURAGES TOOL DEVELOPERS TO NOT PASS ERROR DATA, which greatly increase debugging difficulty. Somethings there are 100 things that possibly go wrong. With error data you can easily know which exact thing is wrong. But with error code you just know "somethin…

There are plans in Zig to allow to include custom information into error stack trace https://github.com/ziglang/zig/issues/14446.

But that is not implemented.

In any case, when debugging annotating error with extra context often is not enough. One often needs a detailed trace of what happens before.

So what I would like to see in any programming language is ability to do a structured logging with extra context from the call stack (including asynchronous support in languages that have that) that has almost zero overhead when the log is not printed.

Various languages and runtimes have some libraries that try to do that, but the usage is awkward and the performance overhead is not trivial.

Re: Why is Zig so cool?

#162

Earlier quoted context omitted.

Sure sometimes... other times you get deadpan replies unironically demanding citations and proof of claims. There's nothing veiled or an insult: what I mentioned is a real factor in why people would read that statement and jump to demanding proof. - If I told a room full of plumbers that Sharkbites are actually sponsored by big Water trying to encourage water wastage, it definitely might not land... but none of them…

You truly don't see how "you didn't get my joke because you're autistic" is not an insult, to people who did you the courtesy of assuming good faith? Not to drag this out, and I don't personally have an autism diagnosis, but seriously this is no way to act in a space where autism is overrepresented.

Did you accidentally double negative?

Re: Why is Zig so cool?

#163

  > Zig  for ( 0..9 ) |i| { }
  > C    for (i = 0; i 
I know an open interval [0..9) makes sense in many cases, but it's counterintuitive and I often forget whether it includes the last value or not. It's the same for python's range(0, 9).

Re: Why is Zig so cool?

#164
post #135

Earlier quoted context omitted.

I feel like the article didn't really hit on the big ones: comptime functions, no hidden control flow, elegant defaults, safe buffers, etc. What Zig really does is make systems programming more accessible. Rust is great, but its guarantees of memory safety come with a learning curve that demands mastering lifetimes and generics and macros and a complex trait system. Zig is in that class of programming languages like…

Zig's generics cause bloat just like any other language with generics--explicit flow control has nothing to do with it. Zig is a good language. So are Rust, D, Nim, and a bunch of others. People tend to think that the ones they know about are better than all the rest because they don't know about the rest and are implicitly or explicitly comparing their language to C.

Zig's generics can potentially, but not necessarily, because Zig's generics are explicitly controlled through comptime functions, which give the developer a ton of control of how the generic code is unrolled. They're also frequently less used in general than Rust generics.

Of course both Zig and Rust are good languages. But my experience, and I believe your experience will be too if you try to compile programs of similar complexity using standard practices of each language, is that Zig compiles much more compactly in .ReleaseSmall mode than Rust does even with optimization flags, which makes it more ideal for embedded systems, in my opinion. I learned this on my own by implementing the same library in both languages using standard default practices of each.

Of course, at the desktop runtime level, binary size is frequently irrelevant as a concern. I just feel that since Zig makes writing "magic" code more difficult while Rust encourages things like macros, it is much easier to be mindful of things that do impact binary size (and perhaps performance).

Re: Why is Zig so cool?

#165

> Zig for ( 0..9 ) |i| { } > C for (i = 0; i I know an open interval [0..9) makes sense in many cases, but it's counterintuitive and I often forget whether it includes the last value or not. It's the same for python's range(0, 9).

I completely agree. One of Zig's big competitors, Odin, has a more explicit syntax for this where `0..<5` is an open interval and `0...5` is closed.

Re: Why is Zig so cool?

#166
post #67
post #8

A neat little thing I like about Zig is one of the options for installing it is via PyPI like this: https://pypi.org/project/ziglang/ pip install ziglang Which means you don't even have to install it separately to try it out via uvx. If you have uv installed already try this: cd /tmp echo '#include int main() { printf("Hello, World!"); return 0; }' > hello.c uvx --from ziglang python-zig cc /tmp/hello.c ./a.out

reinventing nix but worse.

Not even close, that's still imperative package management

Re: Why is Zig so cool?

#167

Earlier quoted context omitted.

The "correct" way is highly context dependent with the added proviso that Zig assumes a low-level systems context. In this context, adding data to an error may be expedient but 1) it has a non-trivial overhead on average and 2) may be inadvisable in some circumstances due to system state. I haven't written any systems in Zig yet but in low-level high-performance C++20 code bases we basically do the same thing when it…

For quite a long time, I have been wondering why I like to code in Raku so much … in a round about way you set me thinking. Perhaps it’s because, in Raku, precision, performance and determinism take a back seat to expediency. (Sorry for the tangent).

Wow, Raku looks like a really interesting language, I'd never heard of it before!

Have you used it in any large projects?

Re: Why is Zig so cool?

#168

Earlier quoted context omitted.

That's not been my experience with Rust. On average produces binaries at least 4x bigger than the Zig I've compiled (and yes, I've set all the build optimization flags for binary size). I know it's probably theoretically possible to achieve similar results with Rust, it's just you have to be much more careful about things like monomorphization of generics, inlining, macro expansion, implicit memory allocation, etc th…

The Rust standard library in its default config should not be used if you care about code size (std is compiled with panic/fmt and backtrace machinery on by default). no_std has no visible deps besides memcpy/memset, and is comparable to bare metal C.

I understand this, but that is a pain that you don't get with Zig. The no_std constraint is painful to deal with as a dev even with no dependencies and also means that if you're working on a target that needs small binaries, that the crates.io ecosystem is largely unavailable to you (necessitating filtering by https://crates.io/categories/no-std and typically further testing for compilation size beyond that).

Zig on the other hand does lazy evaluation and tree shaking so you can include a few features of the std library without a big concern.

Re: Why is Zig so cool?

#169

It’s incredibly silly but I dislike zigs identifier policy. Mixing snake case and camel case for functions is cursed. That said, amazing effort, progress and results from the ecosystem. Bursting on the scene with amazing compilation dx, good allocator (and now io) hygiene/explicitness, and a great build system (though somewhat difficult to ramp on). I’m pretty committed to Rust but I am basically permanently zig curi…

Me too, so I don't follow a convention for private functions. Good thing is you barely interact with ones defined in dependencies.

Prefix anf different naming conventions of C-imported libraries is not less annoying.

Re: Why is Zig so cool?

#170

Earlier quoted context omitted.

For quite a long time, I have been wondering why I like to code in Raku so much … in a round about way you set me thinking. Perhaps it’s because, in Raku, precision, performance and determinism take a back seat to expediency. (Sorry for the tangent).

Wow, Raku looks like a really interesting language, I'd never heard of it before! Have you used it in any large projects?

Had you heard of Perl 6?
Post reply on HN