News for hackers. Stuff that matters.
Re:Data-oriented design or why you might shoot yourself in t... by Zababa on Monday June 28, 2021 @10:02AM (#27662089)
> In all my experience with OOP, it's always been inheritance that is the root of all evil.

I have this "theory" in the back of my head that trees are usually the wrong things to model thing in life but it's what come to us naturally. For example, a blog with categories and sub-catogories for articles (a tree, inheritence) can often describe the content better by using tags (a graph, composition). I think that's because trees are easy to deal with and understand, but graphs are more "open" with what you can do.

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.
Re:Data-oriented design or why you might shoot yourself in t... by oftenwrong on Monday June 28, 2021 @12:12PM (#27663734)
There's a great old (2005) blog post on this topic:

Clay Shirky - Ontology is Overrated: Categories, Links, and Tags

https://web.archive.org/web/20191117162526/http://shirky.com...

Re:Data-oriented design or why you might shoot yourself in t... by state_less on Monday June 28, 2021 @01:07PM (#27664478)
Folks may enjoy some of these old posts too.

https://en.m.wikipedia.org/wiki/Pyrrhonism

For example, putting regions under a cold climates category, might not make sense to someone living near the pole where they would consider the same regions to be warm climates.

Re:Data-oriented design or why you might shoot yourself in t... by Zababa on Monday June 28, 2021 @05:54PM (#27668700)
Thanks, that was a great read. Tangentially related, but I wonder what's the impact of Windows having a really bad search. Maybe people are thus relying more on the folder hierarchies, and that influences how they think?
Re:Data-oriented design or why you might shoot yourself in t... by dexwiz on Monday June 28, 2021 @11:17AM (#27663019)
Humans have a natural tendency to refine a single idea by splitting it into two based on a differentiating factor. This ends up looking like a tree when applied repeatedly. Dichotomous keys for species identification are another example of this.
Re:Data-oriented design or why you might shoot yourself in t... by eska on Monday June 28, 2021 @01:24PM (#27664693)
The problem being that they don't categorize things into one tree, but many. One can view the same thing in different ways. OOP tree hierarchies do not allow that.

It's like trying to categorize your photos in a directory tree. Do you categorize by year first, by person, or location? There is no correct answer. What people want instead is a photo album with tags. The same problem applies to OOP.

Re:Data-oriented design or why you might shoot yourself in t... by Zababa on Monday June 28, 2021 @06:05PM (#27668836)
> It's like trying to categorize your photos in a directory tree

A problem that made me think about tags instead of categories was precisely that: I have photos that I want to organize. I started by organizing them by person with a folder for each person. But how do I handle a photo where multiple people are in it? Tags don't have this problem. Unfortunately file systems don't support tags.

Re:Data-oriented design or why you might shoot yourself in t... by setr on Monday June 28, 2021 @02:08PM (#27665377)
> What people want instead is a photo album with tags

What you really want is hierarchal tags :)

Re:Data-oriented design or why you might shoot yourself in t... by splistud on Monday June 28, 2021 @04:04PM (#27667158)
No, no. We want tags. Later we want hierarchal tags (with some complex workarounds to maintain some legacy thing included in the implementation).
Re:Data-oriented design or why you might shoot yourself in t... by btschaegg on Tuesday June 29, 2021 @02:00AM (#27672334)

  Silly monkeys
  Give them thumbs, they forge a blade
  And where there's one they're bound to divide it
  Right in two
SCNR :)

For everyone that doesn't know the text: I recommend listening to Tool's "Right in two". Although the text originally talks about war and strive, not programming. ;)

Re:Data-oriented design or why you might shoot yourself in t... by prionassembly on Monday June 28, 2021 @03:11PM (#27666366)
Oh man, I have a rabbit hole for you.

https://en.wikipedia.org/wiki/Rhizome_(philosophy)

Re:Data-oriented design or why you might shoot yourself in t... by steveklabnik on Monday June 28, 2021 @05:51PM (#27668663)
Here's a near-decade old talk from me on this exact topic: https://www.youtube.com/watch?v=YfKAScYkGlk

I haven't watched this in like... a long time, so maybe I'd think it's bad now.

Re:Data-oriented design or why you might shoot yourself in t... by prionassembly on Tuesday June 29, 2021 @03:35AM (#27672968)
I recommend Manuel de Landa (stylizes his name to Delanda these days), particularly “Intensive Science and Virtual Philosophy” if your flavor is Anglo style analytical philosophy.

The relevant Deleuze texts (A Thousand Plateaus) can be infuriating if you’re not open to this whole other style of thinking, but Deleuze is no postmodern, he’s a realist and a materialist and sort of a science worshipper, albeit from an angle that would make Neil deGrasse Tyson start bleeding from his nose until he passed out, if he ever grokked it. Start with Delanda, probably.

[googling a little, this isn’t great but isn’t bad for something readily accessible: http://dar.aucegypt.edu/bitstream/handle/10526/3534/DeLanda%... ]

Re:Data-oriented design or why you might shoot yourself in t... by steveklabnik on Tuesday June 29, 2021 @01:03PM (#27678674)
Heck yeah, in full agreement with all of that.
Re:Data-oriented design or why you might shoot yourself in t... by duped on Monday June 28, 2021 @10:36AM (#27662543)
A tree is a graph where all vertices have exactly one path through them.

Trees are often implemented using composition, and inheritance can be graphical (the Diamond Problem is not game over).

Re:Data-oriented design or why you might shoot yourself in t... by jstanley on Monday June 28, 2021 @11:48AM (#27663414)

    A
   / \
  B   C
 / \ / \
 D E F G
This is clearly a tree, but doesn't B have 2 paths through it? A->B->D and A->B->E.
Re:Data-oriented design or why you might shoot yourself in t... by gmfawcett on Monday June 28, 2021 @11:58AM (#27663549)
You're right. The correct definition is that any two vertices are connected by (i.e. are the endpoints of) exactly one path.

Fun fact -- since graph-theory trees are undirected by definition, an inheritance graph is more properly called an arborescence (for single inheritance). For multiple inheritance it's a DAG (with diamond-pattern) or a directed tree (without).

Re:Data-oriented design or why you might shoot yourself in t... by jholman on Tuesday June 29, 2021 @08:49PM (#27683672)
> any two vertices are connected by (i.e. are the endpoints of) exactly one path

No.

You just described a connected acyclic graph, not a tree.

In addition to being connected and acyclic, a tree must also have a root, and is thus implicitly directed.

Re:Data-oriented design or why you might shoot yourself in t... by jhgb on Monday June 28, 2021 @11:50AM (#27663451)
> I have this "theory" in the back of my head that trees are usually the wrong things to model thing in life but it's what come to us naturally.

Have you by any chance read the relevant passages in SICP? It has some things to say about OOP ontologies.

Re:Data-oriented design or why you might shoot yourself in t... by Zababa on Monday June 28, 2021 @04:51PM (#27667936)
I don't think I did, I didn't finish the first chapter of SICP. I'm sure that I'm not the first one to come up with this though.
Re:Data-oriented design or why you might shoot yourself in t... by ferdowsi on Monday June 28, 2021 @02:30PM (#27665698)
Could you link this?
Re:Data-oriented design or why you might shoot yourself in t... by Jtsummers on Monday June 28, 2021 @04:58PM (#27668018)
https://mitpress.mit.edu/sites/default/files/sicp/full-text/...

Possibly that section. It's not about OOP specifically, but about type hierarchies generally.

Re:Data-oriented design or why you might shoot yourself in t... by firethief on Monday June 28, 2021 @02:31PM (#27665711)
You might enjoy this essay from 1965, "A City is Not a Tree": https://www.patternlanguage.com/archive/cityisnotatree.html
Re:Data-oriented design or why you might shoot yourself in t... by necheffa on Monday June 28, 2021 @10:26AM (#27662412)
Except that trees are by definition graphs with specific conditions on direction and cycles.
Re:Data-oriented design or why you might shoot yourself in t... by db48x on Monday June 28, 2021 @10:33AM (#27662508)
Perhaps it is those very conditions which make trees less useful than they at first appear.
Re:Data-oriented design or why you might shoot yourself in t... by firethief on Monday June 28, 2021 @02:35PM (#27665785)
I would argue that its those restrictions that make trees a useful simplification, but also a simplification
Re:Data-oriented design or why you might shoot yourself in t... by potatoz2 on Monday June 28, 2021 @03:32PM (#27666703)
In general yes, but in certain case they force you to simplify in a way that's later painful.