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
The most experience I have is with OCaml: OCaml’s object system can be used as extensible records but they’re a bit limited because you aren’t allowed to refer to the row variable. I’ve heard Purescript does a really good job with their extensible records as well.
1 reply 0 retweets 0 likes -
Replying to @bkase_ @wcrichton
The best use of OCaml’s objects for this: GraphQL serverhttps://github.com/andreas/ocaml-graphql-server …
1 reply 0 retweets 1 like -
Replying to @bkase_ @wcrichton
Maybe there’s a better term than “extensible record” for this sort of language feature. Now I’m curious if there are some interesting power using ECS for this sort of thing similar to that which you shared with visitor pattern
1 reply 0 retweets 0 likes -
Replying to @bkase_
I think so. Ex: common ECS pattern is tags, or data-less components (newtypes). You can dynamically add/remove a tag, and query for elements with a tag: Query<Entity, With<Tag>>. A static extensible system would need Option<Tag> on every entity, so more boilerplate.
1 reply 0 retweets 1 like
Also, a key part of ECS is struct of arrays data layout. Extensible records with subtyping don’t get you this for free. ECS has a central World that stores multiple entities permitting SoA optimization.
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