5 ms·
Isn'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
by geophile 8y ago
Isn'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.
- geophile 8y agoThe difference between a function that depends only on its arguments, and a method which depends only on its aruments and the object is trivial, which is why the distinction bothers me. Another often overlooked difference between the two is that many discussions compare a function with immutable arguments, with a method operating an a mutable object. And then the method is said to be not a function because of the object's mutability. But there is no need for the object to be mutable or for any arguments to be immutable. Perhaps the most substantial difference is a method's dispatch on the object type. But if we're going with Kay's definition, then that is not an essential part of OO, and again, you can imagine dispatch in function invocation too. To summarize: When I start taking apart the different aspects of function invocation and method invocation, I have a very hard time seeing the difference.