← Back to context

Comment by messe

12 hours ago

> even Zig has methods and interfaces

Zig doesn't have interfaces as a language level feature. It uses manually implemented vtables and wrapper methods.

You can do the same in Odin with wrapper functions around a vtable.

There's even syntax-sugar for it in Odin with the `->` operator.

  • This gets you dynamic dispatch, roughly via the C++ route (inline vtables in implementing types). This means you must always pay for this on the types which provide it, even if you rarely use the feature, removing those vtables makes it unavailable everywhere.

    A lot of programmers these days want static dispatch for its ergonomic value and Odin doesn't help you there. Odin thinks we should suck it up and write alligator_lay_egg_on(gator, egg, location) not gator.lay_egg_on(egg, location)

    If we decide we'd prefer to type gator->lay_egg_on(egg, location) then Odin charges us for a vtable in our Alligator type, which we didn't need or want, and then we incur a stall every time we call that because we need to go via the vtable.

  • Oh, nice. I have to admit I'm not all that familiar with Odin, because I've been all-in on Zig for a long time. I've been meaning to try out a game dev project in Odin for a while though, but haven't had the time.

I have not looked much into it. Someone mentioned it once, so i just remembered it.