News for hackers. Stuff that matters.
Re:Data-oriented design or why you might shoot yourself in t... by hcarvalhoalves on Monday June 28, 2021 @11:03AM (#27662869)
Data modelling in OOP is an exercise in coming up with Platonic ideals, resulting in a hierarchical (tree-like) ontology as you try to choose of the atributes as the categorisation dimension, and leaving everything else as properties.

    class Animal
    class Mammal inherits Animal
    class Feline inherits Mammal
    class Cat inherits Feline
    ...
This is different than just asserting facts with data, which can lie in multiple dimensions.

    Is Feline
    Is Mammal
    Is Fluffy
    Is White
    Does Meow
The later is a much more flexible data model as it more closely mimics observed (subjective) reality, and is less disturbed when a new (counter-)example is introduced, but is also harder to reason about than idealised categories.
Re:Data-oriented design or why you might shoot yourself in t... by throwaway894345 on Monday June 28, 2021 @01:27PM (#27664754)
To your point, there are programs that deal in ontologies. These are the only times that it makes sense to care about the relationship between things. For example, an ontology might have a concept of a city and it might know that Munich is a city. But this is all data, it isn't about "types". It never makes sense to write `class Munich extends City {}` for the purpose of your program. Rather, you might have:

    struct Entity {
        name: string,
        parent: Option<Entity>,
    }

    let city = Entity { name: "city", parent: None };
    let munich = Entity { name: "Munich", parent: Some(city) };
That said, if you really wanted to make life hard for yourself, you could use types as data provided your language has a runtime type system and reflection (you could dynamically generate `class City` and `class Munich extends City` when deserializing `[{name: "city", parent: null}, {name: "Munich", parent: "city"}]` or something). But this is the kind of Rube-Goldberg territory that "Kingdom of Nouns" thinking leads us toward.
Re:Data-oriented design or why you might shoot yourself in t... by AdieuToLogic on Tuesday June 29, 2021 @12:22AM (#27671731)
> Data modelling in OOP is an exercise in coming up with Platonic ideals, resulting in a hierarchical (tree-like) ontology as you try to choose of the atributes as the categorisation dimension, and leaving everything else as properties.

Only if that is how you choose to model the problem domain.

> This is different than just asserting facts with data, which can lie in multiple dimensions.

The "Is ..." examples you detail can just as easily be modeled "in OOP" as:

  class Animal {
    private knownFacts = ...

    def is (fact) ...
  }
Without the need for "a hierarchical (tree-like) ontology", since obviously this would be a poor choice in this situation.
Re:Data-oriented design or why you might shoot yourself in t... by hcarvalhoalves on Tuesday June 29, 2021 @10:38AM (#27676422)
Not the same thing, as the facts are now a property of Animal. My second example doesn't even mention Animal. You still have the problem of "putting things into a category" vs. just asserting facts.
Re:Data-oriented design or why you might shoot yourself in t... by meheleventyone on Wednesday June 30, 2021 @02:09AM (#27685464)
There is an implicit subject you are asserting facts about though. You clearly are talking about a fluffy, white Cat in your example. It’s essentially structural rather than nominal typing. The “fluffy, white Cat” is defined by its traits. We could define a type Cat which has a subset of those traits and then be able to use our “fluffy, white Cat” anywhere we can use a Cat. We only name them to avoid having to name all the traits all the time. Doesn’t make it any less object based.

Structural typing is really cool though. An object built from a named, saved recipe will work just as well as something cobbled together on the fly and at runtime you won’t even know which is which. It’s the basis of a lot of general purpose game engines composition based game object interface.

I’ve also found it extremely fun to use with TypeScript.

Re:Data-oriented design or why you might shoot yourself in t... by hcarvalhoalves on Wednesday June 30, 2021 @10:52AM (#27689255)
> There is an implicit subject you are asserting facts about though. You clearly are talking about a fluffy, white Cat in your example.

No, I'm not, because I didn't assert this fact (it's a Cat).

See how hard it is to break free from this mindset of objects.

Re:Data-oriented design or why you might shoot yourself in t... by meheleventyone on Wednesday June 30, 2021 @02:40PM (#27692041)
Right as I said it’s structural typing. It’s implicit that the traits are grouped together to describe something. And individual traits could be grouped together with completely different ones to describe something else. That you choose not to name it doesn’t change that the trait collection applies to fluffy, white Cats whether you like that or not. I can even choose to call it one thing and you can choose to call it something else and the types will remain interchangeable. You can even leave your type anonymous and it will still be interchangeable.
Re:Data-oriented design or why you might shoot yourself in t... by inopinatus on Monday June 28, 2021 @01:55PM (#27665153)
Uh, no. Either of those are possible without leaving the OO paradigm, and only very poorly taught and inexperienced students model data as an object inheritance hierarchy.
Re:Data-oriented design or why you might shoot yourself in t... by coldtea on Monday June 28, 2021 @03:08PM (#27666311)
If only.

Spoken like someone who has never seen any kind of representative sample subset of real world code...

Re:Data-oriented design or why you might shoot yourself in t... by inopinatus on Monday June 28, 2021 @08:28PM (#27670139)
No, the problem is that code by poorly taught and inexperienced developers is rife. Heck it’s on display throughout the threads on this topic; for maximum irony, often as an example of “why <concept> is bad”, the author not realising this merely telegraphs their own limitations.
Re:Data-oriented design or why you might shoot yourself in t... by neolog on Tuesday June 29, 2021 @05:32AM (#27673672)
If f(x) is implemented for white xs and separately for fluffy xs, how do you disambiguate f(x) for x that's both white and fluffy?
Re:Data-oriented design or why you might shoot yourself in t... by wwweston on Monday June 28, 2021 @12:37PM (#27664084)
Hence traits?
Re:Data-oriented design or why you might shoot yourself in t... by beaconstudios on Monday June 28, 2021 @12:43PM (#27664172)
And ECS is fundamentally a trait system!
Re:Data-oriented design or why you might shoot yourself in t... by dkersten on Monday June 28, 2021 @01:18PM (#27664619)
I know all the terms are overloaded nowadays so everything’s kinda unclear but I always wished that ECS components had been called traits, because adding a component to an entity gives it some a trait like “this thing has a position in the world” or “this thing can be drawn” (and perhaps have systems named “behaviors”, because systems add behavior to entities based on the traits/components that they have)

Years ago, when ECS was just starting to be talked about (after Adam Matrins blog posts), I wrote a toy ECS where I used that naming convention. Nowadays I stick to the mainstream terminology since that’s what other people know.

Re:Data-oriented design or why you might shoot yourself in t... by pjmlp on Monday June 28, 2021 @04:41PM (#27667794)
They have, but there is a certain tendency to ignore CS literature.

"Component Software: Beyond Object-Oriented Programming"

https://www.amazon.com/Component-Software-Beyond-Object-Orie...

1st edition, 1998

Re:Data-oriented design or why you might shoot yourself in t... by beaconstudios on Monday June 28, 2021 @02:17PM (#27665503)
Yeah I've commented before that "entity component system" is roughly synonymous with "thing piece thing" or something like that - it's a really bad name because it's so ambiguous. Anything including the term trait would be 1000x better because at least "trait" means something.
Re:Data-oriented design or why you might shoot yourself in t... by bcrosby95 on Monday June 28, 2021 @04:08PM (#27667242)
I think it's named ECS because before then entity+component designs were common in games. ECS generally took the behavior off the C and puts it in the S.