Comment

Comment by AndyKelley

It's an alternative to OOP. You can get there via a series of transformations:

1. Start with OOP (heap-allocated objects with shared base structs)

2. Transform to using tagged unions instead

3. Transform to the approach outlined in the OP (I call it the "encoding" approach in this talk: https://vimeo.com/649009599)

It's handy because you get to use an index to refer to an object, and you get serialization benefits. The zig compiler uses this pattern in quite a few places:

* https://github.com/ziglang/zig/blob/77c63ac36034db577a9287c5...

* https://github.com/ziglang/zig/blob/77c63ac36034db577a9287c5...

* https://github.com/ziglang/zig/blob/77c63ac36034db577a9287c5...

* https://github.com/ziglang/zig/blob/77c63ac36034db577a9287c5...

parent AndyKelley 1 year ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton