4 ms·
I think most languages hide this by default because 99% of people don’t have to deal with it.
by Aeolun 2y ago
I think most languages hide this by default because 99% of people don’t have to deal with it.
- metaltyphoon 2y agoYep. 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.
- Measter 2y agoMost languages handle this by having interfaces/traits/etc. Zig doesn't have those, so you're forced to use these ad-hoc struct instances.
- Symmetry 2y ago99% of people are either better off using a language with a garbage collector or need to avoid heap allocations altogether.
- kunley 2y agoMy questions and remarks had nothing to do with the way how you allocate memory in programs.