5 ms·
> Isn't a method call a message, and the return value a message back? It is! In my view, the point that Alan Kay and Joe Armstrong are trying to make is that
by revvx 7y ago
> Isn't a method call a message, and the return value a message back?
It is!
In my view, the point that Alan Kay and Joe Armstrong are trying to make is that languages like C++/Java/C# etc have very limited message passing abilities.
Alan Kay uses the term "late binding". In Kay's opinion, "extreme late binding" is one of the most important aspects of his OOP [1], even more important than polymorphism. Extreme late binding basically means letting the object decide what it's gonna do with a message.
This is what languages like Objective-C and Ruby do: deciding what to do after a method is dispatched always happen during runtime. You can send a message that does not exist and have the class answer to it (method_missing in Ruby); you can send a message to an invalid object and it will respond with nil (Objective-C, IIRC); you can delegate everything but some messages to a third object; you can even send a message to a class running in other computer (CORBA, DCOM).
In C++, for example, the only kind of late binding that you have is abstract classes and vtables.
-
> Or is it that "true OO" must be asynchronous?
It doesn't have to be asynchronous, but in Alan Kay's world, the asynchronous part of messaging part should be handled by that "dispatcher", rather than putting extra code in the sender or the receiver.
I don't remember Alan Kay elaborating on it, but he discusses a bit about this "interstitial" part of OOP systems in [2]
-
[1] - https://en.wikipedia.org/wiki/Late_binding https://en.wikipedia.org/wiki/Late_binding
[2] - http://wiki.c2.com/?AlanKayOnMessaging http://wiki.c2.com/?AlanKayOnMessaging
- jdsully 7y agoObjective-C is much closer to true object orientation than C++, but IMO Apple neutered it by having the program crash if there was no message handler.
- mpweiher 7y agoIt crashes only if you let it. a) The crash is from the default unhandled exception handler, which will send a signal to abort. So if you just want to crash, you can either handle that particular exception or install a different unhandled exception handler b) An object gets sent the -forwardInvocation: message when objc_msgSend() encounters a message the object does not understand. The exception above gets raised by the default implementation of -forwardInvocation: in NSObject. o := NSObject new. o class -> NSObject n := NSInvocation invocationWithTarget:o andSelector: #class n resultOfInvoking class -> NSObject o forwardInvocation:n 2019-04-22 07:49:12.339 stsh[5994:785157] exception sending message: -[NSObject class]: unrecognized selector sent to instance 0x7ff853d023c0 offset: { (This shows that -forwardInvocation: in NSObject will raise that exception, even if the NSInvocation is for a message the object understands) If you override -forwardInvocation:, you can handle the message yourself. In fact, that is the last-ditch effort by the runtime. You will first be given the chance to provide another object to send the message to ( - (id)forwardingTargetForSelector:(SEL)aSelector; ) or to resolve the message in some other way, for example by installing the method ( + (BOOL)resolveInstanceMethod:(SEL)sel; )[0]. Cocoa's undo system is implemented this way[1], as is Higher Order Messaging[2][3] [0] https://developer.apple.com/documentation/objectivec/nsobject?language=objc https://developer.apple.com/documentation/objectivec/nsobjec... [1] https://developer.apple.com/documentation/foundation/nsundomanager?language=objc https://developer.apple.com/documentation/foundation/nsundom... [2] https://en.wikipedia.org/wiki/Higher_order_message https://en.wikipedia.org/wiki/Higher_order_message [3] https://github.com/mpw/HOM/blob/master/HOM.m https://github.com/mpw/HOM/blob/master/HOM.m
- matwood 7y agoBack when I wrote a lot of obj-c is when I really 'got' message passing vs. a function call. I miss obj-c, but everyone wants to move on to Swift.
- dragonwriter 7y agoWasn't the design decision (and implementation) involved in place log before Apple had anything to do with it?
- jdsully 7y agoNextStep adopted it but did not invent it. Once Apple acquired NextStep and released OS X they were the only major company supporting it and had defacto control over the language. The complaint I have is with NSObject which can be blamed on Next Step. Although another comment pointed out I just didn’t know about a workaround.
- dragonwriter 7y agoThere were two different major mutually-incompatible “flavors” of Objective-C (my first book on Objective-C covered both, and my first Objective-C programming was done on a NeXTcube), one of which originated at NeXT (NextStep was the OS that was NeXTs last major surviving product after they dropped hardware, not the company.)
- lincpa 7y agoExtreme Late binding: for "The Pure Function Pipeline data Flow", attaching data or metadata to the data flow, then the pipeline function parses it at run time, which is simpler, more reliable, and clearer.
- throwaway13337 7y agoI'm surprised the actor model hasn't been mentioned. Isn't this the modern name for what theyre talking about? Completely independent objects passing messages and entirely parallelizable.
- revvx 7y agoAlan Kay answered that himself! :) https://www.quora.com/What-is-the-difference-between-Alan-Kays-definition-of-OOP-and-Carl-Hewitts-Actor-Model https://www.quora.com/What-is-the-difference-between-Alan-Ka...
- jcadam 7y agoMy first exposure to the actor model was with Akka on Scala. After working with it for a little while, I thought "this is what OOP should be, perhaps I just hate broken implementations of OOP (i.e., Java, C++), rather than OOP itself." Heck, I like Ada95's implementation of OOP better than Java's. I keep meaning to give Erlang a try, but just haven't had a reason yet. I do a lot of Clojure, these days :)
- fpoling 7y agoC++, Java etc. all lack proper union types with appropriate pattern matching. So a lot of useful message passing patterns cannot be implemented without too much boilerplate.
- tokyodude 7y agowhat does late binding by you? That sounds like an argument for non-strictly typed languages. Isn't in the strict typing that prevents late binding? The compiler wants to know at compile time the types of all the messages and whether or not an object can handle that message hence all messages must be typed and all object must declare which messages they accept.
- mpfundstein 7y agoObjective c is a compiled language
- Zuider 7y agoObjective C is compiled, yes, but like Smalltalk OOP, the target object of the message is resolved and interpreted by that object at runtime.
- revvx 7y ago> what does late binding by you? Some things that come to mind: - Abstract classes/methods, and interfaces. This is implemented using vtables in C++. - Ability to send messages asynchronously, or to other computers, without exposing the details of such things. You just call a method in another class and let your dispatcher handle it. There was a whole industry built around this concept in the 90s: CORBA, DCOM, SOAP. And Erlang, of course, in a different way. - Ability to change the class/object during runtime. Like you can with Javascript and Lua, calling `object.method = `. Javascript was inspired by Self (a dialect of Smalltalk), so there's that lineage. Other languages like Python and Ruby allow it too. - Ability to use the message passing mechanism to capture messages and answer them. Similar to Ruby's "method_missing" and ES6 Proxies in Javascript. This is super useful for DSLs and a great abstraction to work with. Check this out: http://npmjs.com/package/domz http://npmjs.com/package/domz Remember that you can have some of those things without dynamic typing (Objective-C).
- bad_user 7y agoC++'s vtable is also late binding, since you don't know which implementation you're calling until runtime. And there's no such thing as "extremely late binding". > In C++, for example, the only kind of late binding that you have is abstract classes and vtables. That's not true, you can always have a "send_message(string id)". Few people do it because you lose static type safety. And some languages, like C# and Scala, have dynamic types that allows for the "method_missing" protocol and such features are very unpopular. To be honest I don't see much of a difference. I've worked with a lot of dynamic OOP languages, including with Erlang-style actors and I've never seen the enlightenment of dynamic OOP message passing. And I actually like OOP, but I don't really see the point of all this hyperbole about Smalltalk.
- foobar_ 7y ago> That's not true, you can always have a "send_message(string id)". Few people do it because you lose static type safety. And some languages, like C# and Scala, have dynamic types that allows for the "method_missing" protocol and such features are very unpopular. That is the difference. If every class in C++ had only one method - send_message and each object is an independent thread, you will get how Erlang works. That is how you would do the actor model in C++. Inheritance, Polymorphism is emphasised in Java, C++ and C#, whereas Functional programmers emphasise function objects / lambdas / Command Pattern where you just have one method - calling the function. Infact having just method you no longer need Polymorphism / Interfaces.
- bad_user 7y agoWhat? This has nothing to do with functional programming. FP needs polymorphism too and as a matter of fact FP tends to be even more static. In FP we have type classes, built via OOP in static OOP languages. > Infact having just method you no longer need Polymorphism / Interfaces. That’s false.
- foobar_ 7y agoIt's not. You can use multiple dispatch.