4 ms·
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 "conti
by verdagon 4y ago
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/ https://kristoff.it/blog/zig-colorblind-async-await/
[1] https://medium.com/a-journey-with-go/go-how-does-the-goroutine-stack-size-evolve-447fc02085e5 https://medium.com/a-journey-with-go/go-how-does-the-gorouti...
[2] https://youtu.be/NV46KFV1m-4 https://youtu.be/NV46KFV1m-4
- pharmakom 4y agoNot familiar with Zig but doesn’t colourblindness lose you control over the binding points of the computation? This can be key for optimisation.
- layer8 4y agoIt arguably isn’t fully colorblind: https://gavinhoward.com/2022/04/i-believe-zig-has-function-colors/ https://gavinhoward.com/2022/04/i-believe-zig-has-function-c...
- kbd 4y agoThe 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.
- layer8 4y agoDefinitions aside I’d say that it seems to be a leaky abstraction.
- throwawaymaths 4y agoAs 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.
- layer8 4y agoSection 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.
- a1369209993 4y agoActually, I think "colorblind" is good term for this: zig indisputably has function color (as the article demonstrates), but you can't see it.
- anonymoushn 4y agoHere's a working version of the program gavinhoward was trying to write: https://gist.github.com/sharpobject/49bd88416e68606d7812d609831cc8ae https://gist.github.com/sharpobject/49bd88416e68606d7812d609...
- AnIdiotOnTheNet 4y agoSomething 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.