Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Zig Programming Language (ziglang.org)
99 points by sysadm1n on May 12, 2022 | hide | past | favorite | 22 comments



Something I really appreciate about Zig is its "colorblind async/await" [0].

To my eyes, it's the best of both worlds. It doesn't require a GC like Go's "contiguous stacks" approach [1] or Loom's approach [2]. It also doesn't require coloring like Javascript/Rust's async/await approach, which can sometimes seem like a viral leaky abstraction, causing incidental complexity in the presence of certain patterns.

The main catch is around recursion, but that's not so bad, as Zig as a whole seems to steer users away from recursion anyway, with another interesting feature that detects it at compile time.

I think new languages should be going this direction: focus on making things easier for the user, avoid causing incidental complexity, and keep abstractions zero-cost.

Just my two cents!

[0] https://kristoff.it/blog/zig-colorblind-async-await/

[1] https://medium.com/a-journey-with-go/go-how-does-the-gorouti...

[2] https://youtu.be/NV46KFV1m-4



The mistake that article makes (imo) is that "colorblindness" means at compile-time. i.e. you don't have to define both a sync and an async version of a function. Obviously async vs sync have different representations at run time.


Definitions aside I’d say that it seems to be a leaky abstraction.


As someone who has used this (to enable a single function to be called either preemptively or cooperatively by a surrounding VM)... It's not leaky. To be frank, until you've actually done it, it's hard to see.


Section 4 of the article I linked demonstrates how it’s leaky. Admittedly just in special scenarios, but it means that the mechanism isn’t fully transparent.


Actually, I think "colorblind" is good term for this: zig indisputably has function color (as the article demonstrates), but you can't see it.


Here's a working version of the program gavinhoward was trying to write: https://gist.github.com/sharpobject/49bd88416e68606d7812d609...


Something I appreciate about the implementation is that the suspend/resume primitives make it nigh-trivial to write co-routines, which saved me several nanoseconds per frame in my toy Gigatron emulator's VGA decoding implementation and took a fraction of the time to write and debug compared to the traditional struct-based state machine I wrote first.


Not familiar with Zig but doesn’t colourblindness lose you control over the binding points of the computation? This can be key for optimisation.


Sort of random to see this pop-up out of nowhere.

Very interesting language.

This blew my mind:

https://github.com/ziglang/zig/blob/master/lib/std/multi_arr...


Zig's a regular presence on HN (as is creator Andrew Kelley).


Oh totally. I was just surprised to see a well-known (to people on HN!) language on the front-page w/o any particular news to drive it. HN front page can be random like that. :-) (See also: random wikipedia pages that sometimes show up.)


I really like the ziglings collection for an introduction (mainly for beginners but still lots of fun)

https://github.com/ratfactor/ziglings


Aren't most people aware that Zig exists?


It depends on how often you hit 'reload' on HN. Ten times an hour? you've heard of it. Ten times a month? much less likely.

Most of my work colleagues haven't heard of HN and therefore wouldn't have frequent opportunities to hear about Zig.


If anything, Zig is over-represented on Hacker News with posts and positive mentions, particularly when you compare it to other newer languages. To include the other newer languages getting ignored, bashed, or trolled. Where with Zig, it doesn't get that kind of "heat". But just because Zig might be a "darling" of Hacker News, doesn't mean that's the case in general.

For these newer languages, they need to distinguish themselves, in terms of reasons why people would turn to them. In a world of established languages like C, Rust, Golang, Object Pascal, etc... Why use Zig? The argument to use it over what they already know, might not be there for a lot of people.


Pretty neat language. One of the few that lets you treat allocation failures are regular errors (and makes writing/adding your own allocators really straight-forward).

Although I think HN is probably aware of this lang by now...


Anyone here using Zig for embedded programming?


There's https://github.com/ZigEmbeddedGroup/microzig and other work within the same space.

I've used it for linux-based embedded platforms to both debug and build switches.


I like their take on generic programming.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: