Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> I just want to send a message to an object

Why? Seriously, why is that something you want? Why do you want sending a message to be syntactically and semantically distinct from calling a function?

> The problem people get into with OO (particularly Java, C#, C++) is thinking in terms of method-function calls rather than message sends.

Well, IMHO the problem people get into with OO is thinking that there is something special about sending a message that is different from calling a function. Sending a message is an implementation technique, not a semantically distinct action that should be exposed in the language semantics, and certainly not in the syntax.



Where it matters 'who' gets what powers or responsibilities, sending messages is a powerful way to think about it, not an implementation detail.

In Java it is pretty much just a function call, because the code in the callee has the ability to wreak all kinds of havoc in real Java programs, so the pattern of "messages" is quite imperfectly related to the authorities you're bounding.

More at http://habitatchronicles.com/2017/05/what-are-capabilities/


It would be if virtual method tables weren't a thing, and Java didn't do dynamic dispatch by default.

Then there are Proxy objects, reflection, and invokedynamic as well, for those "doesNotUnderstand:" scenarios.


In most cases, it is really only an implementation technique, but it may be different. In my eyes, sending a message to a probe on Mars is very different from evaluating a function with the probe as an argument. It's sure that, in this case, a Lisp program would transform the function call to a kind of message send anyway with the expectation that the probe is a standalone computation system. OOP approach makes this assumption implicit for everything.


> sending a message to a probe on Mars is very different from evaluating a function with the probe as an argument

Sure. But why do you want that difference to manifest itself in the syntax of your language? What is the benefit of writing, say:

[probe message]

over

send_message(probe, message)

?

> OOP approach makes this assumption implicit for everything.

And that is exactly the problem IMHO because this model is not appropriate for everything. It makes sense when you are dealing with actual physical objects like a Mars probe, but that is rare. Much more commonly you are dealing with abstract objects. If I want to add two numbers A and B, who do I send the message to? A? B? The adder in the ALU? As a programmer, 99.9% of the time I don't care how the operation gets carried out. I just want to write (sum a b) or a+b and let the compiler sort out the details.


In Smalltalk, it is just

probe message

without any brackets, and you can write

a+b

which is the message + send to a with argument b. You just have message passing syntax for everything (Smalltalk has minimal syntax comparable to Common Lisp in size). IMHO it hit the sweet spot of simplicity/readability/expressiveness.

But you cannot judge Smalltalk only from the perspective of its syntax. You need to take into account the context in which it is used. The environment built around it. Then everything starts to make much more sense and forms a vital well balanced system. It is Lisp but different, and I strongly recommend downloading Pharo and to try to figure out how.

I stronlgy admire you; I read "Lisping at JPL" at least dozen times over the years. I really like Lisp, Forth and Smalltalk, and I know that knowing each of them well is worth every penny, even if it may not be obvious on first sight.


> which is the message + send to a with argument b

Yeah, I get that. What I don't get is why I should care that "a+b" means "send the message + to a with argument b" rather than just "add a and b". I see no benefit of the first formulation over the second.

(And thanks for the kind words!)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: