4 ms·
Lack of proper interfaces/traits is also a deal-breaker. One appears to need to do un-readable hacks to get a basic interface in Zig.
by lenkite 3y ago
Lack of proper interfaces/traits is also a deal-breaker. One appears to need to do un-readable hacks to get a basic interface in Zig.
- zozbot234 3y agoInterfaces/traits is syntactic sugar for a function dictionary/vtable. It could probably be done via Zig's compile time subset.
- lenkite 3y agoStandardized language-defined syntactic sugar is deeply important - esp for something as important as interfaces/traits - which are the foundation blocks for setting component contracts in libraries and modules.
- colonwqbang 3y agoNot if the standardised way is worse than the naive way, like in C++. Then I will rather take manual virtual calls, like in C: https://elixir.bootlin.com/linux/latest/source/include/linux/fs.h#L1916 https://elixir.bootlin.com/linux/latest/source/include/linux... It isn't that much more work and it's not something you end up doing terribly often. I think destructors are a much more important to help day to day development and avoid bugs.
- steveklabnik 3y agoIn Rust, traits can be used via a vtable, but also (and the vast majority of the time) as regular old statically dispatched functions. That doesn't mean Zig couldn't do something similar if they want to, just pointing out that it's not always the case that it means dynamic dispatch.
- zozbot234 3y agoI didn't mention run-time dynamic dispatch, only a function dictionary (which C++ calls a vtable). Using traits for bounded subtype polymorphism is much like having a dictionary of functions that can be resolved completely at compile time, making it possible to use monomorphization and static dispatch.
- steveklabnik 3y agoOkay. It's clear we're using some words in very different ways (this is not subtype polymorphism in Rust either) but I see what you're getting at.
- brabel 3y agoAnother problem for me was the lack of error "payloads" (i.e. you can't give some values, like even an error message, with your errors - they're just pure enums without any context) which basically means you need to invent your own custom error system if you don't want your error reporting to suck... but I believe they were going to fix that (not sure if they've done anything yet as I haven't been following too closely, would be happy to be corrected).
- deagle50 3y agoI just pass a "diag" struct to functions that may need to return an error context. It was weird at first but then it dawned on me how much less friction I experienced being able to create error variants on the fly. There's also something to be said for seeing all (or most) of the relevant logic inline vs jumping around trying to make sense of separate definitions.