Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Interfaces are the most important thing Zig needs to implement ASAP

It would also help creating a uniform standard library, for example creating a Writer interface instead of having specific functions for files, sockets, buffers and all kind of types



How are you going to implement interfaces if Zig is without classes in the first place?


Go has interfaces and doesn’t have classes.


For the equivalent thing (interfaces with runtime dispatch and without owning the underlying struct) Zig has explicit vtables. I sort of think any new "interfaces" feature should at least partly be about describing constraints on types at compile time.


i think adding interfaces that are simply enforced at compile time would be a good start

You could create a new type like Dynamic(InterfaceName) that handles dynamic dispatch somehow


There's quite a bit of mildly hairy runtime code necessary to achieve this.




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

Search: