- #1
- 1,231
- 0
I've been thinking about the object paradigm, more specifically the claim that method calling represents "message passing" between the objects. At least in Java, (and also, according to Wikipedia, in Smalltalk) this doesn't seem strictly true to me; it seems more like function calling than actually delivering a message. A true message passing framework should be something like this:
1. Object A receives a message from object B containing some information X about the state of the universe, call it U.
2. On receiving X, Object A takes some action, or takes no action, as it pleases.
3. Object A may pass a message back to object B, or to any other objects it likes. This message contains some information Y about the universe U, perhaps new information that object A generated, or maybe existing information.
This does not seem like it strictly translates into object B calling a method in A and getting a return value back. If the process of B sending a message to A is a method call, the process of A sending information back to B should also be a method call. A should call another method in B to give the "return value" to B; methods should not have a "return value" per se. At least, that's what it seems like a strict interpretation of the "message passing" paradigm would claim.
How about a "pure message-passing" language like the following:
Then the screen would display something like 28.27
Disadvantages?
Advantages?
By the way, I don't like being grumpy. Please just don't reply if nothing about this interests you.
1. Object A receives a message from object B containing some information X about the state of the universe, call it U.
2. On receiving X, Object A takes some action, or takes no action, as it pleases.
3. Object A may pass a message back to object B, or to any other objects it likes. This message contains some information Y about the universe U, perhaps new information that object A generated, or maybe existing information.
This does not seem like it strictly translates into object B calling a method in A and getting a return value back. If the process of B sending a message to A is a method call, the process of A sending information back to B should also be a method call. A should call another method in B to give the "return value" to B; methods should not have a "return value" per se. At least, that's what it seems like a strict interpretation of the "message passing" paradigm would claim.
How about a "pure message-passing" language like the following:
- There is one global procedure, built into the language, called Send(D, B) that sends data D to object B. This procedure represents, abstractly, any communication media between the objects.
- Each object has a method Receive(D, A) that specifies what should be done when data D is received from object A. Receive is not directly callable from anywhere. Calling Send(D, B) from A has the effect of calling Receive(D, A) in B.
- There is a universal language for describing any data to be sent--data should be viewed as true statements about the universe rather than "arguments to a function." XML looks like a good candidate. Validation that the data takes a correct form is essential, and ideally the data contained in any message passed between any two objects would agree with the data contained in any message passed between any other two objects--this is because the data should represent truth about the universe, not just 'input.'
- Each object can then have a bunch of other local functions and local data that it uses itself. One that might be useful as part of the language is Get(x), which extracts data from the set of all truths that the object currently knows.
Code:
D =
<universe>
<circle ID=10>
<radius>3.0</radius>
<area>unknown</area>
</circle>
<universe>
Send(D, calculator) // now calculator will validate and parse the new information that A wants to know the radius of circle 10, and send back to A some XML stating the area of the circle
this.Get(<universe><circle ID=10><area>areaof10</area></circle></universe>)
Send(areaof10, ScreenOutput)
Disadvantages?
- Extremely verbose compared to most languages. This is a big one.
- Figuring out what context information should be provided with a message could be problematic. In this example, I tried to identify the circle as "10," which would probably lead to a conflict quickly. If it were to work in real life, there would have to be a symbol generator (like Lisp's gensym) to give objects unique ID's.
- Sending so much context for a piece of data is inefficient. This problem can probably be optimized significantly at runtime by replacing tags with numeric characters, since all the objects would be aware of the single valid grammar for the program's data.
Advantages?
- Self-documenting, human-readable input and output between objects, since XML is nearly self-documenting.
- The abstraction of messages as "true" data about the universe. Tracking down a bug would be reduced to manually reading through the messages that were passed between objects, and determining when they are true and when they become false. The first time a message is passed that is false, the bug was in the object that generated it. Also, this is somewhat similar to the functional programming paradigm; functions in a functional language can be viewed as "universally true" statements about some data. For example sum [1..40] represents the absolute, universal piece of data which is the sum of the numbers from 1 to 40, and is stateless and will never change. Similarly in this example, areaof10 in <universe><circle ID=10><area>areaof10</area></circle></universe> represents the area of the lone circle in the universe whose ID is 10, which is a theoretically absolute value and won't ever change.
- I think it represents a true "message-passing" programming framework more closely than ordinary languages, which might be interesting to see.
By the way, I don't like being grumpy. Please just don't reply if nothing about this interests you.
Last edited: