News for hackers. Stuff that matters.
Re:The Repeated Deaths of OOP (2015) by lolinder on Sunday June 06, 2021 @11:43AM (#27413899)
Where do we see prototypal inheritance in nature? I can think of lots of examples of composition, but none of prototypes. The closest I can think of would be DNA, but even that would be better modeled as composition in my mind.
Re:The Repeated Deaths of OOP (2015) by aaron-santos on Sunday June 06, 2021 @02:46PM (#27415271)
I see prototypal inheritance in communication. When I communicate that I fried an egg you automatically make a number of assumptions about the properties of that event. If we generally hold the same assumptions then I've transmitted the concept with high fidelity.

However, if I believe that your assumptions about the event won't reify the event in a way that mirrors my own then I will want to override your assumption by communicating extra properties about the event. You can dive a bit into this by way of semantics.

For example, the semantic frame 'cooking'[1] lists 'fry' as a member. What are the salient differences between the parent frame 'cooking' and its member 'fry'? A quick way to explore this is by examining the propositional differences between the frame and member roles. You can imagine the differences between the Instrument and Result roles and how their assumptions differ.

How does this relate back to programming? One way to examine programming languages is through their ontological semantics. As much as we write programs for computers, we also write them for other people. Prototypical inheritance mirrors the structure of languages we already find in nature.

[1] https://verbs.colorado.edu/verb-index/vn3.3/vn/cooking-45.3....

Re:The Repeated Deaths of OOP (2015) by cout on Sunday June 06, 2021 @05:40PM (#27416587)
Mitosis is the cellular equivalent of prototypal inheritance; the cell clones itself, and then you have two cells, each a copy of the original.

You even get an inheritance hierarchy when pluripotent cells divide and become differentiated; the new cell gains functionality missing from the original as genes are turned on.

And yes, there's lots of composition too -- a cell is composed of cytoplasm, organelles, and a membrane (which serves as an interface to the message bus, your blood). The mechanism by which the cells are copied does involve DNA, but it and the proteins involved are an implementation detail.

Re:The Repeated Deaths of OOP (2015) by lolinder on Sunday June 06, 2021 @11:00PM (#27418552)
> The mechanism by which the cells are copied does involve DNA, but it and the proteins involved are an implementation detail.

Well, yes, anything inside the cell is, when modeled as an object, an implementation detail. External behavior is all that matters.

What always strikes me funny about prototypal inheritance is that it seems like a special case of composition, one that just happens to do all the necessary delegation for you.

In the case of the cell, I can model mitosis by having the two cells name their parent as the prototype, or I can define in the code that they're composed of the same stuff and delegate method calls the same way. The end result is the same, but composition is more flexible.

In JavaScript, prototypes have less boilerplate, but it's possible to have a language that eliminates most of the boilerplate for delegation as well (see Kotlin's delegation feature [0])

What do I gain by using a prototype instead of composition with delegation?

[0] https://kotlinlang.org/docs/delegation.html