22 ms·
I still don't really understand what the big idea of message passing compared to a method call is. Is it supposed to be asynchronous? It never seems to be so i
by chrisseaton 8y ago
I still don't really understand what the big idea of message passing compared to a method call is.
Is it supposed to be asynchronous? It never seems to be so in practice. It it supposed to be remotable? So are method calls. Are languages like Objective C and Ruby message passing to some extent? Why is that message passing rather than a method call? What's the essential difference? Is Java message passing?
- azeirah 8y agoThe big idea of message passing is that it's not about message passing, I think what Alan Kay has been trying to say all these year is that we should look at how bacteria communicate, and try to mimic that. They communicate by sending protein "messages" to their vicinity, and if a close-by bacterium knows what to do with it, it processes it, and responds by either sending out their own proteins (message passing), OR change their internals to get receptive to different kinds of messages (change internal state). From this viewpoint, coding starts being about cultivating a literal society of objects (cells). The obvious advantage being that biology scales an immeasurable amount better than whatever architectures we ever come up with. He often gives the example of the internet as a well-designed system, it operates in a similar manner, objects (anything that can self-identify with an IP-address) can join/leave at any point, and the system itself stays alive. I'm not 100% sure if this is what Alan means, but after having following his talks and writings for a couple of years, I think that's the gist of it.
- chrisseaton 8y agoSounds more like what many people would call event-drive architecture, these days. People tell me Ruby is message passing, but it doesn't seem to match your description at all.
- michaelscott 8y agoJust to add to the previous poster's comments, Alan Kay seems to also consider the internal state of a "cell" (or object) to be private and responsive only to external messaging. If you extrapolate this to a network I personally see a "colony" of objects that are not "aware" of each other aside from their neighbours' messages, and the whole thing starts to seem like it has a lot of the features we see in modern functional programming today. I don't think this is particularly coincidental, since functional approaches are born from lambda calculus and Kay mentions in these emails a desire to incorporate algebras into his objects (aside from the biological nature of this type of cell communication). Alan, if you're in the comments section I'd love to hear your thoughts on what you think of the resurgence of functional programming in the modern day and whether anything, other than perhaps languages like Erlang, has approached your original ideal.
- macintux 8y agoI don't think I've watched it previously, and I don't have the time to now, but I have to imagine Joe Armstrong interviewing Alan Kay would at least touch on that (although from one comment it sounds like they didn't do more than that). https://youtu.be/fhOHn9TClXY https://youtu.be/fhOHn9TClXY
- jimbokun 8y agoWatch it! I just watched the whole thing, based on just seeing your link. It does talk about the historical connections between Smalltalk and Erlang, but goes far beyond that to remind us to think more about the bigger problems we need to solve, and get less caught up in doing things just because we have a tool that can do them or other people are doing things that way. I found it truly inspiring.
- rudedogg 8y ago> Alan, if you're in the comments section I'd love to hear your thoughts on what you think of the resurgence of functional programming in the modern day and whether anything, other than perhaps languages like Erlang, has approached your original ideal Someone asked a similar question when he did an AMA, but the answer wasn't clear to me: https://news.ycombinator.com/item?id=11940211 https://news.ycombinator.com/item?id=11940211
- madis 8y agoRuby to me seems to follow this description rather well. The "cells" in close vicinity are the objects in ancestor chain. If the "closest cell" - object's class - can't respond to it, next further, which is its parent, will be given chance and so on. Also you can ask object if they know how to respond with `respond_to?` It's a bit more involved than that - modules can be included and prepended. In a sense "re-arranging the which cells are close and further". Also `method_missing` can be implemented. Beautiful in my opinion.
- deleted 8y ago[deleted]
- inopinatus 8y agoRuby syntax & behaviour is in a hazy middle ground between message passing and method calling. Writing Ruby in a message-passing style feels natural and easy, which is why many Rubyists will recommend it, and doing so enables looser coupling between objects. To me, it's the difference between pulling the strings on a puppet (method calling) vs placing a request to a colleague (messaging). However I don't think anything in the Ruby docs ever claims that it has a message-passing intent. I think the option to write in this style is really a byproduct of duck typing combined with a Ruby object's ability to arbitrarily and dynamically reconfigure its own dispatch table. If Matz really intended a message-passing style, then Object#send would've been split into Kernel#send and Object#receive, and there'd probably be a Message class rather than just using symbols. Given the new shorthand of object.:name in 2.7 for object.method(:name) one could even argue that Matz is drifting Ruby back towards an early binding style. However I don't see myself using that syntax much outside of block parameters to Enumerable methods and the like. Overall I think the stylistic options are a strength and we don't particularly need to resolve the dichotomy to write good Ruby.
- chrisseaton 8y ago> However I don't think anything in the Ruby docs ever claims that it has a message-passing intent. There is of course the `Kernel#send` method, which implies the model is messages being sent. It's not called `call`.
- inopinatus 8y agoI think you mean Object#send? I actually think that's misnamed, I think it should be named Object#receive because that's what happens - you're forcing an object to receive a symbol for (by default) dispatch through its method table. The fact it isn't invoked for regular method invocation is kinda indicative of Ruby _not_ being a pure message passing language, even if we like treating it that way.
- chrisseaton 8y ago> I think you mean Object#send? It's definitely Kernel#send. Object defines no instance methods at all. > Kernel.instance_methods(false).include?(:send) => true > Object.instance_methods(false).include?(:send) => false > Object.instance_methods(false) => [] https://github.com/ruby/ruby/blob/v2_6_2/vm_eval.c#L2163 https://github.com/ruby/ruby/blob/v2_6_2/vm_eval.c#L2163
- profalseidol 8y agoHere's one talk about 'message' in Ruby: RailsConf 2015 - Nothing is Something https://www.youtube.com/watch?v=OMPfEXIlTVE https://www.youtube.com/watch?v=OMPfEXIlTVE But to me, this simply looks like Functional Programming done in an OOP mess.
- pjmlp 8y agoSmalltalk was also influenced by Lisp work being done at Xerox PARC. Map, filter, flapmap, lambdas, symbols, are all there. You can easily do LINQ in Smalltalk-80 without any additional library.
- Pamar 8y agoAre you sure about this? (I haven't read the article yet) - I am asking because what you are describing looks to me closer to https://en.wikipedia.org/wiki/Tuple_space https://en.wikipedia.org/wiki/Tuple_space than "traditional" OOP.
- azeirah 8y agoI said I wasn't sure, but it's what Alan keeps coming back to, his roots in biology and mathematics, scaling, and scaling through communication. It's obviously a bit wooshy, but I'm pretty sure that's the gist of what he intends to get across.
- eternalban 8y agoIt is more than a bit wooshy. The 'solid' parts are all "biology", "mathematics", etc. Alan Kay is, of course, correct that nature provides excellent guidance on how to build resilient systems. I would think that thought is fairly self evident to the subset that is preoccupied with such thoughts. But as the endless exegesis of still-with-us Dr. Kay's historic utterances here and elsewhere demonstrate, there is this very obviously missing link (or unkindly 'hand waving') between "his" 'big idea' and how could we possibly build bio-morphic computational systems with the current state of the art and craft of building software. At which point one could ask the question "why are we discussing these wooshy notions?"
- azeirah 8y agoHis point is, as far as I understand, that we should keep studying biological systems as inspiration for our computational systems, not for the short term (5-10 years) but long term (100-500 years). Sussman equally has famous lectures on the same topic, "we don't know how to compute" The why is not to be practical right now, but to research these ideas to the point where they do become practical, no? But then again, I agree with you, he does keep going on about the same ideas again and again and again, without pointing to the slightly more practical details... Basically ever. It's always "no what we do is bad, all of it, haha don't we suck?" "Look at these cathedrals and ant hills! Why can't we do that???"
- zumu 8y ago> The obvious advantage being that biology scales an immeasurable amount better than whatever architectures we ever come up with. Not sure what you mean by this. In the general case, the hard part of "scaling" is building systems that are easy to reason about / maintain as the complexity / throughput increases. Meanwhile, biology is notoriously difficult to reason about and maintain (think medicine).
- TelmoMenezes 8y agoConventional software engineering is extraordinarily brittle, in the sense that any random mutation to a program is likely to cause catastrophic failure: it is very likely that it will not even be valid anymore, or behave in a completely different way. In this scenario, complexity is the enemy, and we take all the well known-measures that are taken in human engineering to manage complexity. When one dreams of a biological approach, one is interested in replicating the "graceful degradation" aspect of biological structures, which is the opposite of brittleness. If you remove one random cell from your body, it will make virtually no difference. If you remove 1K random cells, you will still not notice anything. If you remove 1M cells, maybe it's not so nice, etc. Biological systems have fewer central points of failure and are much better at adapting to unexpected situations. In this case, complexity can be our friend. I believe it is possible to learn how to design systems more like nature does, and I think this is Kay's dream.
- jdonaldson 8y agoFWIW I had Alan Kay's biologically-inspired "message passing" approach when I wrote a routing library : https://github.com/jdonaldson/golgi https://github.com/jdonaldson/golgi The premise was to start with a standard class-based instance, and then use metaprogramming to autodefine a corresponding ADT for all possible typed responses from the API. This gets around the main problem of message routing (IMHO): Namely, if you're relying on a host system to interpret your message how it sees fit, then you don't really know how it will respond in a given case. Will it error? Will it call something different than what you thought? The solution is just to enumerate every possible response type, and return a corresponding composite type as an ADT. I was doing that manually in a few prior cases, and then realized I could use the macro programming features in Haxe to do something automatically, and put together a library as a POC. I'm certain that FP purists would argue that this is equivalent to some other pre-existing type transformation... but I haven't found it yet. I'm interested if anyone else has been experimenting in this area.
- hota_mazi 8y ago> The big idea of message passing is that it's not about message passing, I think what Alan Kay has been trying to say all these year is that we should look at how bacteria communicate, and try to mimic that. It is such a horrible programming model, though. Making calls and sometimes they get picked up and sometimes not?!? If we're talking remote processes, sure, that's understandable, remote resources are not always available. But in-process? If I call a function on an object, I want the compiler to tell me right now if this code makes sense, and the compiler should stop me right away if that code cannot possibly work once deployed.
- function_seven 8y agoI don't think it's about sending a message into the void and "hoping" that a compatible agent receives the message. Rather, it's about your object not having to know who is handling the message, only what the message is ("what" in both content and type). It's still up to you as the programmer to make sure that you have implemented the other objects to act on whatever message types your code will pass. Just like it's up to you to make sure the method exists in the target class when the caller tries to invoke it. Later on, if you decide to swap out your logging infrastructure for a different one, you don't need to update all the places that called the old one. You just tell your new logger to listen for messages directed at Logger.
- macleginn 8y agoBut is it possible for the compiler to check that some object was actually set to wait to receive a particular message that another object was instructed to send? When coding with method calls, it is possible to accidentally leave a stub instead of method code that is supposed to produce some important side effect, say, but at least you know where to look.
- da_chicken 8y ago> I don't think it's about sending a message into the void and "hoping" that a compatible agent receives the message. Except that is the bacterial model. When you want something done, you signal for it by releasing proteins, and keep releasing proteins until you're satisfied even if the work ended up being done 50 times more than you needed. That's why biological systems so commonly overreact to stimulus. The biological method is to flood communication until whatever demanded response is met. It's the equivalent of a user mashing a button until a program responds, like the elevator button problem. Actually, elevators seem like an extremely good analogy for this kind of asynchronous service system. I understand we're not trying to perfectly mimic the analogy, but I think it's important to see that nature's model, while robust and asynchronous, carries significant problems due to how it communicates. It's that very robustness that we're trying to mimic, so we should expect to inherit some of the problems that go along with it.
- jimmy_ruska 8y agoSussman of SICP fame gave a similar analogy. Not really about messaging but about biology in general - https://www.youtube.com/watch?v=O3tVctB_VSU https://www.youtube.com/watch?v=O3tVctB_VSU
- trevyn 8y agohttps://en.wikipedia.org/wiki/Message_passing#Message_passing_versus_calling https://en.wikipedia.org/wiki/Message_passing#Message_passin...
- chrisseaton 8y agoThis talks about primarily asynchronous message passing, which doesn't seem to be what anyone means in practice.
- pjmlp 8y agoActually that is how NeXT implemented distributed objects. http://www.nextop.de/NeXTstep_3.3_Developer_Documentation/GeneralRef/06_DistributedObjects/IntroDistObjects.htmld/index.html http://www.nextop.de/NeXTstep_3.3_Developer_Documentation/Ge...
- chrisseaton 8y agoThat document says that their messages were synchronous by default, and that asynchronous was something extra built on top just for distributed objects, not how they worked normally and not part of a uniform message passing interface.
- pjmlp 8y agoYes, it was up to you to change the behavior on doesNotUnderstand: methods, but the feature was available, just a matter of defaults.
- deleted 8y ago[deleted]
- amatheus 8y agoI think messages are less bound to types than method calls, more late bound and more reified in some caseS.
- mpweiher 8y agoMessaging is more general. A message can be asynchronous. It can also be synchronous. You can persist messages, replicate them. Distribute them. With a method call, the "caller" control what code gets executed. With a message-send, the sender politely asks the receiver to respond to the message. Is there code executed? Maybe. Maybe not. Maybe the message is ignored. So something like Smalltalk is (roughly) at the minimal end for the capabilities of "messaging" whereas it is either at or slightly beyond the maximal end for "calling a method". The fact that there is a slight overlap makes things difficult, but not impossible, to distinguish. In the articles on Software-ICs[1], they call the flavour of OO "object/message" "Sending a message to an object is exactly like calling a function to operate on a data structure, with one crucial difference: Function calls specify not what should be accomplished but how. The function name identifies specific code to be executed. Messages, by contrast specify what you want an object to do and leave it up to the object to decide how." I am not sure I'd agree with that 100%, and there are tons of ways to argue against it, but I think it's a start. [1] https://blog.metaobject.com/2019/03/software-ics-binary-compatibility-and.html https://blog.metaobject.com/2019/03/software-ics-binary-comp...
- evanmoran 8y agoI think messages help better convey three things: 1) that objects are acting like async, independent machines (I picture the erlang actor model, but maybe that’s a stretch.). This makes messages a more natural way to emphasize that these actions can happen across networking or threading boundaries; 2) the message is explicitly not inheritance and therefore doesn’t contain implementation. This means it’s really a messaging contract and only the interface matters! 3) redirecting, storing, or replaying messages are each very powerful concepts that lead to many useful features (networking state, save/load, undo/redo, logging, debugging). Thinking in these terms is much harder to express with functions, so I see this as messages are the _data_ of function calls, and function calls are more the _act_ of calling. That said, I’d love to hear other’s take on this as well. The differences from functions are subtle and it doesn’t help that we use the same/similar words to mean different things.
- scroot 8y agoIn most systems, try to call a method that doesn't exist on something. It will bark at you. In the types of OO systems Kay discusses, it's up to the receiver to determine whether or not to respond to a message and how to behave if it doesn't "understand" the message. That's how you get maximum polymorphism as well -- for example, all kinds of objects are "cancelable" if they respond to / understand the message #cancel, etc, etc
- mamon 8y agook, so truly oriented OO system needs some equivalent of Ruby's method_missing() ? Is that's what you mean?
- chrisseaton 8y agoI'm not sure method_missing is powerful enough to do message passing. It's method_missing, not method_received. You can't intercept message that already have a method defined for them. The sender chooses which method to call, and may call method_missing. It's not entirely up to the object how to respond to a message.
- gridlockd 8y agoWhether a method call qualifies as message passing in the OOP sense would depend on the language semantics. In any event the caller must not be specifying the function to call (i.e. it's a virtual method in C++ terms) and it should be possible to send a message that is not understood without causing a fatal error (requires reflection in many languages).
- Gibbon1 8y ago> and it should be possible to send a message that is not understood without causing a fatal error I do that sort thing in C via a SendMessage(msgType...) idiom. Instead of a bunch of functions, you have one function and a message Type and some data. If the destination doesn't know what to do with a message of type whatever it just spits that back.
- 0815test 8y agoThis is basically how defunctionalization is implemented. I'm less confident about the "what if the destination doesn't know about the msgType you sent" issue, because defunctionalization itself is a whole-program technique where the destination context has to know what to do with your function call. But your solution (i.e. raising an error condition) looks reasonable enough.
- coldtea 8y ago>I still don't really understand what the big idea of message passing compared to a method call is. For one, the binding happens much later. Second, messages you can't handle can be automatically forwarded and delegated. Third, it doesn't have to be local, the receiver could be a server in the other side of the world. Redux action dispatchers are kind of messages...
- kragen 8y agoI think saying "the binding happens much later" in 2019 is unnecessarily hard to understand. The binder in Unix has always been called a "linker"; the term "binder" was used in a bunch of PARC systems and consequently in Oberon, but since Unix-influenced systems (and I think DEC-influenced systems like CP/M) called it a "linker", the verb "link" has entirely supplanted the verb "bind" for this purpose, about 30 years ago, except when people are repeating the phrase "late binding" or "late-bound" without understanding what it means. So I'll explain what it means here, because it took me a lot of years to understand that "late binding" was a specific concrete concept rather than a vague generality. What we're talking about when we say "binding" or "linking" is the process of associating a reference — typically to a function that's being called, though occasionally to a global variable or something — with a particular referent, such as a particular chunk of executable code. When we say that some "binding" is happening "late", what we mean is that this linking is happening at run-time — at the time of the actual call, not even at program startup time, as with ld.so. Doing the linking (or "binding", as some people called it 40 years ago) at call time means that the same function call can invoke a different function every time you call it. Of course, that's what method calls in languages like JS, Lua, or Python do, as well as function calls in languages like Scheme, JS, Lua, or Python. By contrast, calls to C++ or Golang methods are compiled into machine-code calls to particular machine-code functions, unless the methods are virtual or via an interface, respectively, and it's the linker that links (or "binds") these calls to their callees. (Unless they're inlined, blah blah.) This, of course, gives you immense flexibility, at the expense of some performance and predictability. You're right to distinguish message passing from late binding, as message passing is more general.
- dwoot 8y agoThe way I've come to understand this is that a method is how an object responds to a message or messages. I've come to learn that a lot of us think about creating classes first and the conversations second. Conversations and the messages in these conversations should, often times, tell us whether creating a class right now is needed. I really follow the philosophy of putting off decisions to lock oneself into an abstraction too early on (not enough information/data) and preserving flexibility. Often times, a struct is enough for carrying pieces of a related idea around. It isn't until its internal state or a need for it to have conversations with other objects do methods defined in a class make sense. Furthermore, classes without methods are just state containers. I write some Ruby and some of the basis of my ideas come from Sandi Metz's book, "Practical Object-oriented Design in Ruby" where she describes message-passing.
- FPGAhacker 8y agoMicroservices probably exemplify this idea. And Erlang style languages/development. It’s just an idea. It seems to work well in some situations, given the successes owed to Erlang and dev architecture like microservices. People have their war stories about terrible experiences too.
- agumonkey 8y agoIt's a fuzzy one I'm not sure I understand either. One thing though "tru OO" guys often complain of false message passing based on function call. Others here are hinting at asynchronous vs synchronous. Very likely to be what Kay meant. Another thing to me, is that message interactions mean standalone data exchange. As if to design your interfaces to accept very small but complete objects as communication protocol. Rather than passing structures to be modified. I'm not sure it is even true at all but that's a feeling I got from Kay's talks and his biology metaphor. In a way it's a stateless bus connecting stateful objects (probably trying to minimize their internal state space as much as possible too).
- Xixi 8y agoMessage passing is much more general than method call. If you look at Erlang/Elixir (making the assumption that Erlang processes are akin to objects): messages can be sent to any process running on any node on the network, the answer (if required) can come from a third process, messages can be stored for future processing. And since processes may be created or die dynamically, and messages sent over the network may timeout, there are built-in tools to handle all the failure modes. Method calls in C++ or Java are rather primitive, in comparison. Though of course you can build/emulate all of that on top of either. After all, the Erlang VM (BEAM) is written in C...
- deleted 8y ago[deleted]
- deleted 8y ago[deleted]
- geophile 8y agoIsn't a crucial difference that a method call may have a return value, while message passing never does? Now method calls and function calls: to me they're the same thing. After over 20 years of Java, I still stumble over that terminology. They're function calls, OK?
- chrisseaton 8y agoPeople call Objective C and Ruby message passing, but they have return values. Nobody's definitions here seem consistent or applicable to implemented systems! Crazy how much a well-known idea can be so hard to pin down.
- pjmlp 8y agoSmalltalk messages also return values.
- galaxyLogic 8y agoI beg to differ. Functions are stateless things they should always return the same result for the same inputs. Methods on the other hand have access to the state of the object whose method you call and result of the method-call can depend on not only its arguments but also on the state of the recipient-object. Of course depending on the language a keyword like "function" need not create something that always returns the same result for the same arguments. JavaScript for instance. A method is "associated with" an object and has access to the private state of that object. Of course depending on the language that might differ but we are here talking about what is an "OO language".
- vidarh 8y ago"Under the hood" most language implementations just implements methods as functions with the object as one of the parameters and privileged information about how to interpret the object structure. This illustrates the difficulty of differentiating these things, as pretty much everything we do is "just" syntactic sugar. But of course that syntactic sugar often has substantial impact on how we think.
- jlg23 8y agoTechnically there is no difference. In a closed universe both compile down to the same. The difference lies in the approach to software design[1]. [1] If I could be more specific, Mr. Kay would have been so 30+ years ago.
- spc476 8y agoI don't view there being much of a difference. I wrote about this a few months ago (http://boston.conman.org/2018/11/21.1 http://boston.conman.org/2018/11/21.1) but the idea of it came years before.
- bunderbunder 8y agoI've always wanted to understand the distinction to be that messages are always by value, never by reference. Think of the actor model, or a microservices-type system: Individual objects don't have any shared memory, so all they can do is pass around messages that describe information they know. In short, the distinction between a system with method calls and one with message passing is whether or not it allows for spooky action at a distance. But this distinction isn't really carried through by all the systems that claim to be based on message passing.
- galaxyLogic 8y agoThat is an important distinction yet I prefer to think of message-passing a bit more generally. There are different kinds of message-passing, the one that avoids spooky action is just one of them, a good one but still not the only one. Say I look over my cubicle wall and see you and "send" you a paper-airplane. The paper-airplane is the message, I can assume you will become aware of it having landed on your cubicle. Perhaps there is a question written on the paper. Because I have good eyesight I can spookily already see your answer without you having to send that paper-airplane back to me. It's still message-passing even though it is spooky. The real distinguishing feature of "message passing" I think is that the recipient is free to interpret the messages they receive, and that no-one else can, that no-one else can modify the "mental state" of the message-recipient than they themselves, as a response to the messages they receive.
- bunderbunder 8y agoI think I must be missing a detail, because it feels to me like your spooky example of peeking over the cubicle wall is in direct conflict with the idea that nobody can modify an object's mental state except by passing objects to it. If you're really only allowed to communicate by passing messages, then, to me, that would imply that there's some sort of "no peeking" rule.
- galaxyLogic 8y agoSay I send you a mutable object as an argument of a message / method-call while holding on to that same object in some variable as well. You modify that object without telling me. Does that mean you are spookily communicating with me? I would say no because you are not communicating with me at all. I am unaware that you have modified the object. I can ask that object about its state and that way detect that somebody has changed it. But how can I ask it about its state? Only by sending it a message/calling its method, IF I am using an "Object-Oriented Language". There is nothing spooky about multiple observers having access to the same shared mutable object, is there? They can still only extract information from it by - sending a message - in an Alan Kayesque Object Oriented language. But in a hybrid language like JavaScript where I can directly read and write and even delete fields of an object it is spooky, this value was just here and now it is no longer and I don't know why because somebody else somewhere deleted that field.
- bitwize 8y agoIn Java, calling a method foo on an object compiles to different things depending on the class of the object. The compiler determines whether the object has a method foo, and compiles the call either into a direct jump or an indirect jump through the object's vtable. (Which slot in the vtable is fixed by the compiler.) With message-send semantics as in Smalltalk or Objective-C, the compiler only knows the method's name, and calling a method foo compiles to the same thing irrespective of the object's class. It's the object's job to determine what foo means, and it will do the dispatch to determine which method to use, or if no method matches, call a missing-method handler.
- chrisseaton 8y agoThat sounds like it's only an implementation difference. You could compile Objective C with a profiling or global analysing compiler that compiles method calls to different things depending on the class of the object if you wanted to, and you could compile Java with an approach that compiles to the same thing regardless of the object's class if you wanted do. But message passing is always described as a programming model, not an invisible implementation detail.
- galaxyLogic 8y agoThe difference described in the post one level up is basically the difference between C++ virtual and non-virtual methods. It is not an invisible thing. Virtual methods behave differently than non-virtual ones.
- chrisseaton 8y agoBut that's what I mean - you could implement non-virtual methods using the same technique as virtual methods, if you wanted to. And using static analysis or profiling you could implement virtual methods as non-virtual methods. Are you telling me that if I turn on a compiler optimisation my message passing program suddenly becomes a method call system? So the difference cannot be what it compiles to.
- ridiculous_fish 8y agoOne imperfect but compelling analogy is the HTTP GET request. A GET request was originally envisioned as a request for a file at a path. `http://host/get/this/thing.data` http://host/get/this/thing.data` The requestor decides what to do (give me this file), the host obeys. Nowadays we understand GET requests as abstract. The requestor makes a request, but it is the host who decides what to do with it: forward it somewhere else, emit an error, dynamically generate the content, return a real file, serialize and cache the request, etc. The client doesn't know and can't know what the server does. Notice in particular that hosts are expected to handle arbitrary URLs sensibly. Java has no support for this, but Ruby and ObjC have these sort of facilities: forwarding, dynamic replies, etc. It's up to the libraries to make good use of it.
- pjmlp 8y agoActually Java has partial support for it via proxy classes. https://docs.oracle.com/javase/9/docs/api/java/lang/reflect/Proxy.html https://docs.oracle.com/javase/9/docs/api/java/lang/reflect/...
- bmn__ 8y ago> A GET request was originally envisioned as a request for a file at a path. […] Nowadays […] the host who decides what to do with it: […] dynamically generate the content Nope, a very early description of HTTP – years before 1.0 – already mentions that. https://www.w3.org/Protocols/HTTP/Methods.html https://www.w3.org/Protocols/HTTP/Methods.html
- galaxyLogic 8y agoMethod calls are messages. Same thing. To better understand what Alan Kay is talking about it helps to know a specific fact about Smalltalk, the language he invented. Unlike in C++ or Java or JavaScript Smalltalk objects can not have public data-members. They can only have methods. Methods can read and write the "instance variables" inside the object, no-one else except the object itself can. This means that objects can only communicate by calling methods. They can not read or write data stored into another object. Thus they are totally ignorant about the "implementation" stored inside other objects. They can "send it messages" meaning call its methods. But because all communications with an object are processed by the methods of that recipient object, the recipient object itself is wholly responsible for the MEANING and effect these method-calls have. "Message-passing" is an apt metaphor for such a thing. This is "message passing" because it is the recipient object who must ALWAYS INTERPRET ALL messages it receives. Therefore method-calls have the semantics of "messages". Whereas in Java and C++ and JavaScript the caller of an object can also directly modify other objects without the object being modified being "aware" it is being modified. The "meaning" of such modifications is then determined by whoever makes them. Say I store into your object the property "you.age = 253". But what does that mean what does that signify? Only the other object which stored that value "knows" why it did that, what it "means" what implications it should have for the later progress of the program. So even though in Java etc. you can implement message-passing simply by calling methods, you can also do other things to the object from their outside than only send them "messages". An Object-Oriented language according to Alan Kay (according to me) then is one where the only way objects can communicate with other objects is by calling methods i.e. by message passing, never by modifying the objects directly from their outside.
- wtroughton 8y ago100% agree that in object-oriented programming, only the object itself should care about its internal state. The object should know about its behaviors and what state changes are actually valid. In Java, many projects overuse getters and setters. Getters and setters break encapsulation. More so public setters since they allow any piece of code anywhere can change the value of an object's internal state at any time. Consider a class Person. A person has a name, SSN, salary. Let's assume name and SSN cannot be changed. What about salary? We don't have to add a setSalary() method. Instead, we should have something like: public void acceptNewJob(Job newJob) { salary = newJob.getSalary(); }
- eternalban 8y agoI can send a "what time is it?" message to an object even if that object has no idea what that message means. I can not call a method that isn't there.
- joe_the_user 8y agoI think the idea of message passing is a lot like "pure" functional programming. What matters isn't simply that the language does message passing but that the programmer can count on all communication being by message passing. Then you have a broad "polymorphism" that guarantees all the parts of the system just take messages and do things. Obviously, in practice that could be implemented by function call but having the confidence that programming units are only going to receive messages makes it easier to think about the system - hopefully.
- PopeDotNinja 8y agoMessage passing in Java is basically joined at the hip with method calls, at least in the same thread. On new Foo(), you call .bar(), and then block until you get a response. Because you know .bar() is there before you ever call it, it's not super obvious what the message passing is. Now imagine something like Erlang, which is a complete mind screw for someone used to writing sync code. The FooProcess can send the BarProcess an async message, but there is no guarantee the message got to BarProcess recieved the message, or that the BarProcess or that it will even be alive when the message arrives. Maybe a good place to start is to read up on method_missing and message passing in Ruby.
- hota_mazi 8y agoWhy would you ever want this kind of uncertainty in-process? If I have an object that lives in my process and I want to call a function on it, I rely on the compiler to tell whether that function exists or not. If it doesn't, why would I ship with code that will never work? If we're talking remote calls, sure, there is never any guarantee that the recipient has that method, or that it's even listening anyway. All of that to say that that whole discussion between function call or message passing is a waste of time and irrelevant in programming.
- PopeDotNinja 8y ago> All of that to say that that whole discussion between function call or message passing is a waste of time and irrelevant in programming. I once felt that way. Then I learned Elixir, and the actor model is my favorite thing of all time. It has amazing abstractions for dealing with concurrency.
- mercer 8y agoThere must be a better way to discuss this topic than to just shit all over something that other people think is a good idea, no? How can you know with such certainty that you're correct and everyone else is just being stupid? EDIT: Err, never mind. You're apparently inclined to shit on anything you don't like in most of your comments.
- 8y ago
- igouy 8y ago"A message is a request for an object to carry out one of its operations. A message specifies which operation is desired, but not how that operation should be carried out. The receiver, the object to which the message was sent, determines how to carry out the requested operation. For example, addition is performed by sending a message to an object representing a number. The message specifies that the desired operation is addition and also specifies what number should be added to the receiver. The message does not specify how the addition will be performed. The receiver determines how to accomplish the addition. Computing is viewed as an intrinsic capability of objects which can be uniformly invoked by sending messages. … A crucial property of an object is that its private memory can be manipulated only by its own operations. A crucial property of messages is that they are the only way to invoke an object's operations. These properties insure that the implementation of one object cannot depend on the internal details of other objects, only on the messages to which they respond. Messages insure the modularity of the system…" pages 6 & 7, [pdf] Smalltalk-80 The Language and its Implementation http://sdmeta.gforge.inria.fr/FreeBooks/BlueBook/Bluebook.pdf http://sdmeta.gforge.inria.fr/FreeBooks/BlueBook/Bluebook.pd...
- chrisseaton 8y agoI don't know what to say - that just sounds like normal method calls to me. Why do we need the term 'message passing' on top of that, which seems to additionally confuse people around synchronous or not?
- deleted 8y ago[deleted]
- galaxyLogic 8y agoConsider JavaScript's "call" if you are familiar with that: You say somefunk.call (someObject, ...someArgs) The function executes in the context of 'someObject' meaning it can read and write its fields with expressions like 'this.color = "blue"'. You could say that somefunk() is a method and you are making a method-call. But it is not a method of 'someObject'. Yet by calling it you CAN manipulate the fields of someObject. JavaScript is NOT the type of "Message passing/Object-Oriented" system like Smalltalk-80. You can communicate with objects, meaning share information with them, meaning read and write their fields, by means other than their methods only.
- randomdata 8y agoIn many languages, a method is simply a function that has some kind of binding to the object. In fact, some languages treat methods as nothing more than syntax sugar around passing the object as the first argument to a function. To call a method is to call a function and the technical details that goes along with that. Messages differ in that you are only providing a description of what you want the object to do. The object then interprets the message and decides how to respond. That may mean calling a method that matches the description, but it may choose to do something else entirely. An object may even handle messages that have no corresponding methods at all. The big idea is that an object can reason about the message before it handles it.
- mikekchar 8y agoI'm not Alan Kay, nor do I pretend to think like him, but having done some experiments on what I think he was suggesting I think the distinction between message passing with a method call is a bit of a red herring. Message passing can obviously be implemented with function calls. When he's talking about "messages" he's not referring to implementation. He's referring to constraining where data can be accessed when doing a computation. Because a lot of people (including me) have a Simula based view of "object oriented", we tend to think of objects as data structures with functions attached to them. Alan Kay had a different view, as far as I can tell. He viewed objects as being a collection of abilities. You could invoke these abilities by sending the object a "message". How you send that message is irrelevant. The important thing is that the object is not a collection of data, but rather the object contains the program state necessary to provide the ability (and nothing more). One of the things he talks about (I can't remember if he does in this specific email exchange, though) is the idea that once the data is inside the object, you can't actually access it any more. It becomes a detail that the programmer doesn't have to worry about. As an example, it's tempting to look at a point on a 2D plane as a tuple containing an X coordinate and a Y coordinate. However, let's forget about the data and instead think about the actions that you might want to do with a point. You might want to construct a vector from it (normalised from the point 0,0). You might want to translate it (by giving it a vector). You might want to rotate it around another point at a certain angle, etc, etc. From the outside perspective there is no reason to access the X and Y coordinates. We don't have to care about what a point object contains -- we only have to care about what messages it responds to. But how is that really different that having a struct with X and Y and a bunch of functions attached to it? I thought pretty hard about this and one of the things I thought about was what if we approached this in a more functional, rather than imperative fashion. Alan Kay was, after all, coming from an FP background. For example, let's say that we have a collections of points and we want to "indent" them by pushing them all to the right based on the X coordinate of an existing point. Our "normal" approach would be to get the X coordinate of the existing point and then add that value to the X coordinate of all the other points. Instead, though, what if we had a method on Point that accepted a function. The method would call the function and furnish the x coordinate (we could call it "with_x", perhaps). Now we can use that method to construct a Vector, setting the x coordinate of the vector to the x coordinate of the point. We could then map over our collection of points and translate using the vector. The difference is subtle, but I think it's important. With a struct, we essentially export program state out of the Point object. With this more functional approach, we run the function within the Point itself. In other words, we are asking the Point to construct the Vector itself, by sending it a message. I think this is what Alan Kay meant when he talks about message passing. It's not about the mechanism of the passing of messages, it's about where the computation is performed as a result of that message passing. In our example, the X coordinate of the point never "leaks out" of the point. We can use it in the context of the point, but we can just grab it in the middle of some other computation. Is that distinction important? I've tried to write some non-trivial code in that style and I really liked how it came out. I'm not sure if it's "better" than doing it another way, though. I would have to spend considerably more time with that style of programming to say for sure.
- jfoutz 8y agoRuby and objective c are both strongly influenced by small talk. Yes. That’s on the right track. I’d say messages are very loosely coupled compared to a function or method call. In c everything is laid out by the linker. You can play games with function pointers, of course, but that is tricky. Message passing isn’t really resolved till the message is actually sent. Late binding I think it’s called. Objective c gives so much control, you could add remoting at dispatch time. I think Java’s methodinvoker is pretty much it for Java. You can implement an interface at runtime. But you don’t control dispatch quite as deeply. Micro services approximate some of Kay’s ideas really well, but imho they give up too much control over dispatch. In ruby or objective c you can hijack the dispatch system in a way that’s really hard to do with micro services
- wsc981 8y agoI think this quote from a blog post [0] gives a pretty clear from the Objective-C perspective: I was thinking recently on the idea of “sending a message” versus that of “calling a method”. Those familiar with the capabilities of the Objective-C runtime understand that there is a difference. Most compiled languages refer to methods and functions internally as offsets. The offset indicates that if one were to move a certain number of spaces in memory from a designated starting point, then we would find the beginning of the instructions that correspond to the desired function. This has the advantage of being very fast. The starting point is known at compile- time, and so to find the appropriate section of memory takes just a couple of instructions. However, it has the disadvantage of being inflexible. This is where most compiled languages differ from Objective-C The Objective-C runtime maintains a list of all the methods and functions it knows about. The list has two components per entry: the name of the method (known as the method’s “selector”) and the location of the method in memory. When an object attempts to “call a method”, it is really behaving quite differently. When the code was compiled, the compiler translated the code [anObject doMethod:aParameter]; into objc_msgSend(anObject, @selector(doMethod:), aParameter); (basically. The actual behavior is slightly more complex but is all explained in the documentation). The objc_msgSend() function does a dynamic lookup. It knows the name of the method it’s supposed to find (@selector(doMethod:)), and so it goes and looks up in its big list where it can find what it’s supposed to do next. This allows us to do some really interesting things. For example, we can modify this list whenever we want. We can swap out values of the list, so that instead of selector A executing the code for A, selector A might instead point to the code for B. The runtime allows us to do some very powerful stuff. The disadvantage is that this is (as you might imagine) slightly slower than directly jumping to the appropriate section in code. However, the difference is minute. Each message send takes just a couple nanoseconds longer than a regular method call. --- [0]: http://davedelong.tumblr.com/post/58428190187/an-observation-on-objective-c http://davedelong.tumblr.com/post/58428190187/an-observation...
- WA 8y agoAnd here I was thinking, I was the only one who was utterly confused by Apple‘s docs about Objective-C and calling everything slightly different than I was used to. Also, isn’t it odd that your replies all say something different what message passing actually is?
- shrimpx 8y agoAt the risk of coming off as snarky toward Alan Kay, whom I respect tremendously, I believe the Kay-official answer to the question "what is Kay oop?" is "you just don't get it." Which for me has always raised a flag. We all know how to call methods, exchange messages, and raise and subscribe to events, yet there is always the implication that we haven't yet understood the real meaning of Kay oop, as if there's some gold nugget of knowledge yet to be gleaned. Pretty sure there's no nugget.
- _pmf_ 8y agoI think the "you don't get it" refers to the knee jerk reaction of trying to map methods to messages.
- schwurb 8y ago> I believe the Kay-official answer to the question "what is Kay oop?" is "you just don't get it." Which for me has always raised a flag. There are at least two problems at work here: 1. The words that Alan Key is (rightly) using are overloaded, since other languages adopted the OO term, but interpreted them differently. This adds to miscommunication: The words sound familiar, but their meaning might be subtly or drastically different. 2. The advantages of OO as thought by Alan Key are hard to convey if not by hands-on experience. Debugging and developing programs in Smalltalk is really fun and effective, but I had to write my thesis in a Smalltalk company first to appreciate it. This is an instance of the "blob problem" as termed by Paul Graham. Many Non-Lispers have a hard time appreciating the benefits of powerful metaprogramming, and reading articles about it won't change that. They might peak interest, but one has to play around some time with those concepts to gain a feel for what benefits and limits are.
- SignsOfABeast 8y agos/blob/blub/
- augustk 8y agoImplementation-wise, with message passing the operation to be performed is sent as a parameter to a message handler. A method call, on the other hand, is simply the invocation of a subroutine stored in a record field (a function pointer). The following article provides some examples in the Oberon programming language which I found clarifying: https://www.miasap.se/obnc/data-abstraction.html https://www.miasap.se/obnc/data-abstraction.html
- vidarh 8y agoI like to see message passing as method calls as conceptually about who is responsible. A method call is "done to" an object. The caller decides which code is invoked. It does so with information about the object or its class, but ultimately the object has no direct say. Message passing on the other hand conceptually grants the object the role of deciding what happens to a message. Message passing is often implemented in terms of method calls for the simple cases, but an object has the ability to dynamically define how a message should be handled based on state that may be known to the object but not the caller. A typical Ruby example (and Ruby is a good example - it "stole" most of its object model from Smalltalk) is Ruby ORMs like Sequel (same applies to most Ruby ORMs) that dynamically define accessors for columns etc when connecting to a database and dynamically querying the database for the schema. In Ruby, method calls is a veneer - you can define a method that looks like it's just like a C++ method call, decided at the callsite, but at runtime the receiving object can be redefined at any point, up to and including changing which methods the object responds to on an object-by-object basis, or defining "method_missing" so that what looks like method calls are entirely dynamic. > It it supposed to be remotable? So are method calls. I'd say there is a difference in degree of complexity in remoting. In a message passing system you typically do not need to have any kind of definition of the interface available client side. E.g. Drb for Ruby lets you expose any Ruby code over a network connection this way. E.g. here is a real example, using the "pry" Ruby REPL. Server side: $ pry [1] pry(main)> require 'drb/drb' => true [2] pry(main)> drb = DRb.start_service("druby://localhost:8787", self); nil => nil [3] pry(main)> def hello; puts "Hello world"; end => :hello [4] pry(main)> Hello world [4] pry(main)> [5] pry(main)> def hello; "Hello world"; end => :hello The above exposes "self" which is this case is the "main" object of that Ruby instance, but you can pass it any object you want, and all public instance methods on that object will then be remoted, and any objects returned from those methods will be remoted dynamically as needed. It then defines the "hello" method on main after the server has been set up. Doesn't matter when the methods are defined, as long as they're there when you call them. The redefinition of "hello" in [5] happens after I've called hello the first time from the client (the "Hello World" in [4] was triggered by the client. The redefined version returns the string to the client instead of printing it on the server: $ pry [1] pry(main)> require 'drb/drb' => true [2] pry(main)> client = DRbObject.new_with_uri("druby://localhost:8787") => #<DRb::DRbObject:0x000055828909f220 @ref=nil, @uri="druby://localhost:8787"> [3] pry(main)> client.hello => nil # Here we redefine "hello" on the server. [4] pry(main)> client.hello => "Hello world"