runarorama / runarorama.github.com

9 stars 3 forks source link

Objects, Identity, and Concept-Formation #10

Open tomer-ben-david opened 10 years ago

tomer-ben-david commented 10 years ago

Perfect :)

jedharris commented 10 years ago

I don't feel attacked, thanks for the warning :-)

However I do think there's some confusion here. You could be talking about some sort of induction over actual programs, over theoretical analyses of programs, over programming language constructs, or likely other things. Induction over these different fields gets different results.

I guess your post is correct that people are using the term "objects" in an undisciplined way that doesn't lend itself to any clear definition.

However I think there is a clear concept of "object" that can be found by induction over programming languages that implemented what they called "objects". Historically "object oriented programming" was defined in Simula and Smalltalk, and then a bit later in various Lisp dialects. (I'll set aside Actors as it never was in wide use and tends to be confusing.) These all had a single common idea / mechanism at their core, so induction over that set of languages does yield a clear concept.

The idea is just untyped polymorphic invocation, where a call site "delegates" the choice of which routine to call to the actual value of a parameter (or multiple parameters in the case of some Lisp dialects). Parameters that support this kind of delegation are "objects" or (sometimes) "first class objects". This gets fancied up in all sorts of ways but the basic idea is common to all these languages.

Notice that inheritance, class hierarchy, etc. are not part of this idea. Those vary more between languages and are sometimes omitted entirely. In my opinion we're only recently getting languages with adequate solutions in those areas, and there's no clear single idea to induce from examples.

To do any useful induction here we have to abstract from arguments about formal semantics. My limited understanding is that fully duplicating this behavior in a typed language is (was?) difficult so it has tended not to be treated as a valid concept. But from the point of view of a programmer it is completely valid to say there's a common concept -- taking no position on whether it is good.

There is a simple argument from modularity that this idea is worthwhile. Introducing new kinds of data with new behaviors that are (from the programmer's point of view) compatible with the logic of existing code can require local modification to the existing code to handle the new kinds of data. This idea provides a way to avoid much or all of that modification, without much if any added overhead in the source. Lacking other ways of achieving this, the mechanism used in these programming languages was very worthwhile.

I can believe that sufficiently sophisticated type semantics, type inference, etc. could completely replace the functionality of this call target delegation (or dispatching) but as far as I know that still hasn't happened in any widely adopted language, and I'm not even sure there's a theoretical proposal for doing it that would completely get us there.

bacota-github commented 7 years ago

Long ago "object oriented programming languages" were those that supported classes, inheritance, and polymorphism through virtual methods/late binding, and "object oriented programming" was the use of those features in software design.

So, the term really does (or at least did) mean something.

runarorama commented 7 years ago

Haskell's type classes are, well, classes. They support subclassing (i.e. "inheritance"), and Haskell certainly has polymorphic types as well as "virtual methods" via implicit dictionary passing. So is Haskell programming "object-oriented programming"?

bacota-github commented 7 years ago

Maybe Haskell can be used for object oriented programming :)

Bjarne Stoustrup in "What is Object Oriented" (https://pdfs.semanticscholar.org/8984/821866c708b10d4b45a2e601ef660d11b5e5.pdf_ defines the "object oriented programming paradigm" as "Decide which classes you want; provide a full set of operations for each class; make commonality explicit by using inheritance." (It suffers a little from brevity, but note that inheritance is key.)

I'm not arguing that "object oriented programming is good", but that it implies some very specific techniques, such as inheritance and late binding. Although, I concede that the term has been much abused. To quote (well, paraphrase) again from the same paper: "Object Oriented is Good. Ada is Good. Therefore Ada is Object Oriented."