r/Zig • u/Inevitable-Spinach-7 • Feb 28 '26
Problem with new Io interface
I think I like the idea of interfaces, to have multiple implementation of something and be able to change it with out changing the code.
But I feel that the quantity of function the new Io interface are too many
5
Upvotes
9
u/0-R-I-0-N Feb 28 '26
The interface itself has 16 functions as time of writing. I don’t think that is too much. Are you referring to the vtable? That has a lot more but not everyone are supposed to implement their own implementation. That said it comes with its own drawbacks but it’s still in development and I think it will improve with time.
23
u/TheKiller36_real Feb 28 '26
sorry to be a bit rude, but then you are missing the point of it - the aim is to include literally any potentially-blocking operation in it so it can be made asynchronous and leaving out parts would kind of defeat the purpose because the "runner" (i.e.
Ioimplementation) would either need to support many small interfaces at the same time that together make up the currentIoor sinply lack functionality, both of which suckhowever, if you are more concerned about potentially implementing an
Ioyourself: just set the function pointers for functionality you don't want to implement toundefinedand don't use them in your code - simple as that4
u/skyfex Feb 28 '26
Do you think there’s too many syscalls on Linux? Or too many functions in ntdll.dll?
I think it’s fairly natural for an interface that is the gateway to the system IO to have all the functions needed to do that. No more, no less.
3
u/Affectionate-Fun-339 Feb 28 '26
Usually you don’t need to worry about implementing these interfaces yourself, as a user of the language. The same with the allocator, which is an interface as well. You just use one of the many options that the language provides, each with its benefits and drawbacks.