The benefit of traits vs. classes is that I can add *functions* to existing objects without needing to modify a monolithic definition. The benefit of ECS vs. structs is that I can add *data* to existing objects without needing to modify a monolithic definition.
-
Show this thread
-
Replying to @wcrichton
I feel like ECS is a hacky workaround for a language’s lack of extensible records in the same way the “visitor pattern” is a hacky workaround for a language’s lack of algebraic data types and pattern matching. Or is there something else there?
1 reply 0 retweets 1 like -
Replying to @bkase_
I’ve never seen a language with extensible records, so can’t say 100%. I searched and found Elm, but it just lets you define type aliases. You would need structural subtyping to make that work as traits do. Are you thinking of a specific lang?
4 replies 0 retweets 0 likes -
Replying to @wcrichton @bkase_
Also, I don’t think the visitor pattern is a hack. Rustc code base uses visitors for ADTs. Visitors with default behavior mean if ADT adds a new variant, existing visitors don’t break which is valuable sometimes. Visitor vs match is open vs closed.
1 reply 0 retweets 2 likes
And for ECS, it’s a dynamic way of extending records. It’s hacky in the same way dynamic typing is. Basically just means every object becomes a Map<TypeId, Type>. But you could conceptually do the extensible stuff statically with enough language support.
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
cognitive psychology. PhD