3 ms·
You will need to pass that for synchronous IO as well. All IO in the standard library is moving to the Io interface. Sync and async. If I want to call a functi
by messe 10mo ago
You will need to pass that for synchronous IO as well. All IO in the standard library is moving to the Io interface. Sync and async.
If I want to call a function that does asynchronous IO, I'll use:
foo(io, ...);
If I want to call one that does synchronous IO, I'll write:
foo(io, ...);
If I want to express that either one of the above can be run asynchronously if possible, I'll write:
io.async(foo, .{ io, ... });
If I want to express that it must be run concurrently, then I'll write:
try io.concurrent(foo, .{ io, ... });
Nowhere in the above do I distinguish whether or not foo does synchronous or asynchronous IO. I only mark that it does IO, by passing in a parameter of type std.Io.
- tcfhgj 10mo agowhat about non-io code?
- messe 10mo agoWhat about it? It gets called without an Io parameter. Same way that a function that doesn't allocate doesn't get an allocator. I feel like you're trying to set me up for a gotcha "see, zig does color functions because it distinguishes functions that do io and those that don't!". And yes, that's true. Zig, at least Zig code using std, will mark functions that do Io with an Io parameter. But surely you can see how that will lead to less of a split in the ecosystem compared to sync and async rust?
- tcfhgj 10mo ago> But surely you can see how that will lead to less of a split in the ecosystem compared to sync and async rust? not yet
- torginus 10mo agoThis creates the drill-down issue we see with React props where we have to pass objects around in the call chain just so that somewhere down the line we can use it. React gets around this with the context hook and which you can access implicitly if it has been injected at a higher level. Do you know if Zig supports something of the sort?
- messe 10mo agoIt doesn't and likely never will. This has been a non-issue for years with Allocator. I fail to see why it will be a problem with IO.
- throwaway17_17 10mo agoI think the view that it’s a non-issue comes down to familiarity via language usage. I am on the ‘everything explicit all the time’ team and see no issues with Allocator, or the proposed IO mechanism. But, programmers coming from other languages, particularly those with an expectation of implicitness being a semantic and syntactic feature can not envision programming without all of the alleged time saving/ergonomic ‘benefits’. I have had multiple ‘arguments’ about the reasoning advantages, complete lack of time loss (over any useful timeframe for comparison), and long-term maintenance benefits of explicitness in language design. I have never convinced a single ‘implicit team’ dev that I’m right. Oh well, I will keep doing what I do and be fine and will support in whatever ways I can languages and language development that prioritizes explicitness.
- rowanG077 10mo agoWell it's not a "problem" in the sense that it's a blocker. But it's also not an improvement over standard async await in other languages. Which is not bad, don't get me wrong.
- torginus 10mo agoWhat do you mean by non-issue? You just accept passing it around in every function, and now passing around another param for io as well? Or do you create a context struct and pass that around?
- messe 10mo ago> You just accept passing it around in every function In every function that needs to allocate yes. Sometimes, it'll be stored in a struct, but that's rare. And not every function needs to allocate. > and now passing around another param for io as well? Yes. Not everything needs to do Io. You should try reading some idiomatic Zig code. Ghostty would be an example (as would much of the Zig standard library).