Live data from Hacker News

Zig – SPIR-V Backend Progress

ziglang.org

21–30 of 75 posts

Re: Zig – SPIR-V Backend Progress

#21
post #20

I really love everything about zig except the language itself. The governance, the culture, all of it seem really cool, but reading https://ziglang.org/learn/why_zig_rust_d_cpp/ I still don't get _why_ I would use it. To an untrained eye, it seems like go, but with manual allocation. Or an imperative-only rust. Like it has some features of all the languages it competes with, but not the ones that would make me reach…

I really think the best way to describe it is an attempt to replace C. Go is only like C in that it's simple. But it's clearly not a direct C replacement. It's not a great language for writing an OS or embedded code. Rust may replace C in many contexts, but Rust is much more like C++. It adds a lot of complexity to the language and the compiler. I think it does it in a much better way than C++ so I think it is more l…

I think there are very few places where C makes sense and C++ doesn't. Its mostly legacy things like the Linux Kernel, or more aesthetic projects like demoscene or suckless. Where its easier to agree to write C instead of trying to agree on what subset of C++ to use (even then its usually C with a mishmash of C++ ergonomics)

That said, leafing through the first chapters of "Expert C Programming" should dissuade anyone of the idea that C is a simple language. It'll leave you amazed anyone's been able to write working programs in it

Re: Zig – SPIR-V Backend Progress

#22

I really love everything about zig except the language itself. The governance, the culture, all of it seem really cool, but reading https://ziglang.org/learn/why_zig_rust_d_cpp/ I still don't get _why_ I would use it. To an untrained eye, it seems like go, but with manual allocation. Or an imperative-only rust. Like it has some features of all the languages it competes with, but not the ones that would make me reach…

If you want something better than C you aren't going to reach for Go (GC) or Rust (complexity).

Zig looks like a good middle ground.

Re: Zig – SPIR-V Backend Progress

#23
post #21
post #20

Earlier quoted context omitted.

I really think the best way to describe it is an attempt to replace C. Go is only like C in that it's simple. But it's clearly not a direct C replacement. It's not a great language for writing an OS or embedded code. Rust may replace C in many contexts, but Rust is much more like C++. It adds a lot of complexity to the language and the compiler. I think it does it in a much better way than C++ so I think it is more l…

I think there are very few places where C makes sense and C++ doesn't. Its mostly legacy things like the Linux Kernel, or more aesthetic projects like demoscene or suckless. Where its easier to agree to write C instead of trying to agree on what subset of C++ to use (even then its usually C with a mishmash of C++ ergonomics) That said, leafing through the first chapters of "Expert C Programming" should dissuade anyon…

> That said, leafing through the first chapters of "Expert C Programming" should dissuade anyone of the idea that C is a simple language. It'll leave you amazed anyone's been able to write working programs in it

What footguns are present in C bit not in C++?

C++ has all the footguns from C and adds multiple more. C++ is not a replacement for C, in the same way that a spacecraft is not a replacement for a Cessna.

Re: Zig – SPIR-V Backend Progress

#24
post #21

Earlier quoted context omitted.

I think there are very few places where C makes sense and C++ doesn't. Its mostly legacy things like the Linux Kernel, or more aesthetic projects like demoscene or suckless. Where its easier to agree to write C instead of trying to agree on what subset of C++ to use (even then its usually C with a mishmash of C++ ergonomics) That said, leafing through the first chapters of "Expert C Programming" should dissuade anyon…

> That said, leafing through the first chapters of "Expert C Programming" should dissuade anyone of the idea that C is a simple language. It'll leave you amazed anyone's been able to write working programs in it What footguns are present in C bit not in C++? C++ has all the footguns from C and adds multiple more. C++ is not a replacement for C, in the same way that a spacecraft is not a replacement for a Cessna.

"Correct" modern C++ eliminates whole classes of problems. You can of course still write C code, but no one would merge that in to their codebase

Theyre both complicated languages in their own way :)

Re: Zig – SPIR-V Backend Progress

#25
post #20

I really love everything about zig except the language itself. The governance, the culture, all of it seem really cool, but reading https://ziglang.org/learn/why_zig_rust_d_cpp/ I still don't get _why_ I would use it. To an untrained eye, it seems like go, but with manual allocation. Or an imperative-only rust. Like it has some features of all the languages it competes with, but not the ones that would make me reach…

I really think the best way to describe it is an attempt to replace C. Go is only like C in that it's simple. But it's clearly not a direct C replacement. It's not a great language for writing an OS or embedded code. Rust may replace C in many contexts, but Rust is much more like C++. It adds a lot of complexity to the language and the compiler. I think it does it in a much better way than C++ so I think it is more l…

Zig feels like Modula-2 or Object Pascal had been redone with a C like syntax, so an improvement over C with features available in other programming languages since 1978, however it still has some of the flaws like use after free, and the solution is the same as C has been using for decades, debug allocators.

Re: Zig – SPIR-V Backend Progress

#26
post #24

Earlier quoted context omitted.

> That said, leafing through the first chapters of "Expert C Programming" should dissuade anyone of the idea that C is a simple language. It'll leave you amazed anyone's been able to write working programs in it What footguns are present in C bit not in C++? C++ has all the footguns from C and adds multiple more. C++ is not a replacement for C, in the same way that a spacecraft is not a replacement for a Cessna.

"Correct" modern C++ eliminates whole classes of problems. You can of course still write C code, but no one would merge that in to their codebase Theyre both complicated languages in their own way :)

Unfortunately plenty of folks do merge it into their codebases, including at companies that seat on WG 21, easily found on their Github projects.

Re: Zig – SPIR-V Backend Progress

#27
post #4

I really love everything about zig except the language itself. The governance, the culture, all of it seem really cool, but reading https://ziglang.org/learn/why_zig_rust_d_cpp/ I still don't get _why_ I would use it. To an untrained eye, it seems like go, but with manual allocation. Or an imperative-only rust. Like it has some features of all the languages it competes with, but not the ones that would make me reach…

Try reading zig code. For me its much more readable than the other languages, and does not suffer the fact go doesnt have language level errors. Local allocators are very useful and if you dont think so, perhaps you havent dwelved too deeply into systems programming or the language isnt targeted for you.

The dot syntax used everywhere really confuses me. I get its use in struct fields, or for defining anonymous structs, but what is this one for? (Some kind of module-level enum space, where .sampler and .unknown are defined previously?)

  const Sampler = @SpirvType(.sampler);
                             ^

  const Image = @SpirvType(.{ .image = .{
    .usage = .{ .sampled = u32 },
    .format = .unknown,
              ^
  } });
Everything else about zig is quite readable, but this gets me every time. Maybe I'm being dumb though.

Re: Zig – SPIR-V Backend Progress

#28
post #10

Side question as I am following zig only losely and do Go Programming: Zig has the feature that you can drop in your allocator from the caller. Now with 0.16 you also "bring your own IO" implementation with you. And for my understanding this looks like the pattern Go uses with its Context package, where you pass in transitive data, cancellation signals and timers to for example stop an SQL query in server B, since a…

not really sure what you're asking. but time is now part of the io interface, so you can pretty easily write your own io implementation that just stubs out to the stdlib's default io content and has custom time functions if you want to try something funky. This is pretty close to what you are asking for (and in terms of functionality, equivalent). I say go for it and see what happens, report back!

Thank you for your response. So time as you mentioned can be made explicit.

I am probably looking for something like the request context with timers and cancellation signals propagating through the call chain like in gRPC but more fine granular.

So you could implement arbitrary response times of functions. So you could say like:

This whole request must finish in 5 seconds, otherwise abort.

And these 5 seconds can be made very low so that you reach latency of NUMA vs Single CPU.

I don't know how you call this, maybe "latency budget"

Re: Zig – SPIR-V Backend Progress

#29
post #10

Side question as I am following zig only losely and do Go Programming: Zig has the feature that you can drop in your allocator from the caller. Now with 0.16 you also "bring your own IO" implementation with you. And for my understanding this looks like the pattern Go uses with its Context package, where you pass in transitive data, cancellation signals and timers to for example stop an SQL query in server B, since a…

What Zig is doing is called "capability passing". I don't know if the Zig team is aware of this field of work, or have independently arrived upon it, but that's what is achieved by passing IO, memory allocators, and other stuff around.

The core idea is that you create a "capability" for any action you want to track, such as using IO, allocating memory, or in your example making cross core or cross server calls. Now to perform these actions code has to have access to the capability. It's a very simple, but powerful, model.

The Effekt language formalizes this, and adds safety properties: https://effekt-lang.org/ Scala 3 also has this.

The papers are pretty readable, if you ignore the middle bits which go into the formal models.

Re: Zig – SPIR-V Backend Progress

#30

I really love everything about zig except the language itself. The governance, the culture, all of it seem really cool, but reading https://ziglang.org/learn/why_zig_rust_d_cpp/ I still don't get _why_ I would use it. To an untrained eye, it seems like go, but with manual allocation. Or an imperative-only rust. Like it has some features of all the languages it competes with, but not the ones that would make me reach…

C is over 50 years old, but it is still more or less the lingua franca of computing. The world benefits from having "C with some improvements from 50 years of learning". The world also benefits from having featureful languages that are a huge divergence from C, but it also just needs a language that provides a thin cross-hardware abstraction over the asm layer and some conveniences over writing raw asm. We don't need…

Those improvements were already available in languages that predated C, but were seen as programming with straightjacket from UNIX crowds.

Note that even C creators proposed changes to WG 14 (not accepted), and later on moved on with their own approaches with Alef, Limbo and finally Go.

Post reply on HN