Live data from Hacker News

Why is Zig so cool?

nilostolte.github.io

201–210 of 527 posts

Re: Why is Zig so cool?

#201
post #103

Earlier quoted context omitted.

Interesting, but really in need of some examples.

I would highlight `std::launder` as an example. It was added in C++17. Famously, most people have no idea what it is used for or why it exists. For low-level systems it was a godsend because there wasn’t an official way to express the intent, though compilers left backdoors open because some things require it. It generates no code, it is a compiler barrier related to constant folding and lifetime analysis that is par…

I don't think that's quite right. For DMA you would normally use an empty asm block, which is what's typically referred to as a "compiler barrier" and does tell the compiler to discard everything it knows about the contents of a some memory. But std::launder doesn't have the same effect. It only affects type-based optimizations, mainly aliasing, plus the assumption that an object's const fields and vtable can't change.

For example, in this test case:

https://gcc.godbolt.org/z/j3Ko7rf7z

GCC generates a store followed by a load from the same location, because of the asm block (compiler barrier) in between. But if you change `if (1)` to `if (0)`, making it use `std::launder` instead of an asm block, GCC doesn't generate a load. GCC still assumes that the value read back from the pointer must be 42, despite the use of `std::launder`.

Re: Why is Zig so cool?

#202
post #196
post #190

Earlier quoted context omitted.

It seems pretty common to me?! Java is developed that way. So is Rust. And many others. What exactly do you see as different in Zig?

I don’t think Java and Rust were so ok with completely removing features. For example, in Zig 0.15 they completely overhauled the io, meaning all libraries now have to rewrite up usage. Just to make sure they did it right

> Just to make sure they did it right

Let me guess: they didn't, and now there is a third-party "right" way to do it.

(We've been here before, many times.)

Re: Why is Zig so cool?

#203
post #196
post #190

Earlier quoted context omitted.

It seems pretty common to me?! Java is developed that way. So is Rust. And many others. What exactly do you see as different in Zig?

I don’t think Java and Rust were so ok with completely removing features. For example, in Zig 0.15 they completely overhauled the io, meaning all libraries now have to rewrite up usage. Just to make sure they did it right

Semantic major/minor version 0.15 means it's still in development. It's not supposed to be stable. Going from 0.14 to 0.15 allows breaking changes.

Try making a similar change between version 5.0 and 6.0, with hundreds of thousands of existing users, programs, packages and frameworks that all have to be updated. (Yes, also the users who have to learn the new thing.)

Re: Why is Zig so cool?

#204
Do you need pointer arithmetic? I think that's the one feature a modern C replacement should do away with. The other being support for arithmetic with unsigned types.

Re: Why is Zig so cool?

#205

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…

Yeah, every single newbie programming language designer starts with a maximalist position of "exceptions are hard, just return an error code", and then end up inventing their own shitty, ad-hoc and malfeatured exception handling system.

I want off this ride.

Re: Why is Zig so cool?

#206

Earlier quoted context omitted.

The standard models are pretty bad a zig right now since the language is so new and changes so fast. The entire language spec is available in one html file though so you can have a little better success feeding that for context.

> The entire language spec is available in one html file though so you can have a little better success feeding that for context. This is what I've started doing for every library I use. I go to their Github, download their docs, and drop the whole thing into my project. Then whenever the AI gets confused, I say "consult docs/somelib/"

Just use gh_grep mcp and the model will fetch what it needs if you tell it to, no need to download from GitHub manually like this

Re: Why is Zig so cool?

#207

Zig is not cool. It's a mediocre new language, missing key features needed for industrial development, like destructors or overall memory safety. But for some reason it's overhyped.

It's ""simple"", so low-information, high-blogspam software developers have something to talk about instead of programming.

Re: Why is Zig so cool?

#209
Author is apparently unaware of alternatives like Ada, Object Pascal and Modula-2, where most of those "innovations" were already available.

It is kind of interesting that packaging the same ideas with a C like syntax suddenly makes them "cool", 40 years later.

Re: Why is Zig so cool?

#210
post #198
post #190

Earlier quoted context omitted.

It seems pretty common to me?! Java is developed that way. So is Rust. And many others. What exactly do you see as different in Zig?

Java and Rust have surpassed 1.0 version a long time ago, so they don’t remove features left and right on each feature release. Not that it’s a bad thing. Python removes stuff, and it takes time to upgrade to new versions.

And Zig has surpassed 1.0 or where is the argument?
Post reply on HN