5 ms·
Interfaces can still be expressed using vtables. You just have to write the vtable yourself rather than have the language do it for you. Also, Zig's tagged uni
by badtuple 5mo ago
Interfaces can still be expressed using vtables. You just have to write the vtable yourself rather than have the language do it for you.
Also, Zig's tagged unions (enums with payloads in Rust) are really ergonomic and often what you want instead of interfaces. Alot of languages that use interfaces simply don't expose a good way of doing it so everyone reaches for interfaces by default. But if you don't need an actual interface then this way you don't even have to pay the cost of runtime dynamic dispatch.
- redrobein 5mo agoAre there any plans to add syntax sugar for interacting with vtables?
- metaltyphoon 5mo agoSadly no, as fas as I'm aware. I can't think of creating vtables manually every time I need to create interfaces, I guess Zig is not for me.
- slopinthebag 5mo agoYeah I don't understand why a language cannot automate something that routine and boilerplate-y. Oh well, people like it so I won't judge, I'm happy we have choices for what languages we use. Just wish people would choose safe ones :/
- lenkite 5mo agoWish we could bribe Andrew Kelley to add a built-in for this. There are only a couple of regular ways that everyone creates these vtables. Might as well just standardize it.
- sali0 5mo agoI feel like a std lib module would be sufficient.