3 ms·
Yep. For some reason they want to make it boilerplate to write interfaces. Its so pointless
by metaltyphoon 2y ago
Yep. For some reason they want to make it boilerplate to write interfaces. Its so pointless
- kristoff_it 2y agoThere are a few different ways of implementing interfaces, each with different tradeoffs, so it's not boilerplate :^)
- 0x696C6961 2y agoI'm only familiar with the vtable approach, what other ways are there?
- throwawaymaths 2y agofieldparentptr. The zig allocators used to use this because it enabled allocator interfaces without type erasure, but it was found to have a minor but real performance penalty as it is impossible for any compiler to optimize for this in scenarios that are useful for allocators. Other interfaces might actually have the opposite performance preference
- cgh 2y agoIf you control every implementation (ie you aren’t writing a library where others will implement your interfaces), then tagged unions are a simple way to accomplish this. See the bottom of this page: https://www.openmymind.net/Zig-Interfaces/ https://www.openmymind.net/Zig-Interfaces/
- kcbanner 2y agoIt's not pointless, because you get to select exactly the design pattern that is best for the situation. Other languages may decide this for you.