Hacker News new | ask | show | jobs
by PaulHoule 636 days ago
Hickey is great at trash-talking other languages. In the case of Car you might build a set of builders where you write

   Car.builder().make(“Buick”).model(“LeSabre”).build()
Or in a sane world code generate a bunch of constructors.

In the field of ontology (say OWL and RDF) there is a very different viewpoint about ‘Classes’ in the objects gain classes as they gain attributes. :Taylor_Swift is a :Person because she has a :birthDate, :birthPlace and such but was not initially a :Musician until she :playsInstrument, :recordedTrack, :performedConcert and such. Most languages have object systems like Java or C++ where a Person can’t start out as not a Musician but become one later like the way they can in real life.

Notably in a system like the the terrible asymmetry of where does an attribute really belong is resolved, as in real life you don’t have to say it is primary that Taylor Swift recorded the Album Fearless or that Fearless was recorded by Taylor Swift.

It’s a really fascinating question in my mind how you create a ‘meta object facility’ that puts a more powerful object system on your fingers in a language like Java or Python, for instance you can have something like

   taylorSwift.as(Musician.class)
which returns something that implements the Musician.class interface if

   taylorSwift.isA(Musician.class)
where

   TaylorSwift instanceof MetaObject.class
2 comments

Well, that's what C++ templates were made for.

White your code to work on Musicians, pass Taylor Swift in.

If she's not a musician, your code won't compile.

What I am talking about is more dynamic, although meta-objects could be made more static too.

Particularly, I am not a Musician now but if I learned to play an instrument or performed at a concert I could become a Musician. This could be implemented as

   paulHoule.isA(Musician.class)                                  # false
   paulHoule.as(Musician.class).playsInstruments()                # an empty Set<Instrument>
   paulHoule.as(Musician.class).playsInstruments().add(trumpet)
   paulHoule.isA(Musician.class)                                  # now true
I really did build a very meta object facility that represented objects from this system

https://en.wikipedia.org/wiki/Meta-Object_Facility

in an RDF graph and provided an API in Python that made those objects look mostly Pythonic. Inheritance in MOF is like Java so I didn't need to use any tricks to make dynamic classes (possible in RDF) available.

This is interesting. It seems like a logic language (like Prolog) would work more naturally.
builder() .... build() Rich Hickey got something right. This is about as far from the idea behind DOP as it gets.
That's on Java, though. Many other languages such as Kotlin, Swift, etc. have better ways of dealing with this, e.g. in Kotlin

  Car(make = "Buick", model = "LeSabre")