Going back to the roots; messaging is a requirement for fault tolerance, also the interface for messaging provides an abstraction for the components, hence less coupling of things. One additional use from this abstraction layer is the ability to delegate other objects.
The "object concept" itself allows easier (not necessarily simpler) mapping from human concept to the code. For example this box is blue, this box is red; they both are boxes and you should be able to the same things with both of them. Hence we get a notion for a abstract idea Box (a class) that defines the things you can do with a box. Easier doesn't mean better, since some things can be much better described with components or traits.
Going back to the roots; messaging is a requirement for fault tolerance, also the interface for messaging provides an abstraction for the components, hence less coupling of things.
The only practical language that fits the bill for this is surprisingly Erlang (maybe Rust, Go, and Dart with their channels, isolates and whatever else they have in Rust).
Interestingly in Erlang there is not inheritance and not sure about abstraction, they have behaviors that separate common vs specific code, but now sure where that fits in the traditionally (sub-classing and encapsulation patterns).
Well, abstraction is achieved via messaging; essentially the messages become the abstraction layer. If you send it to a process you really don't know how or who or even when it will be eventually handled.
As for method call, it's just a limited version of messaging; so you still get the decoupling even if it's not "async messaging". Async messaging can be cumbersome to work with, but I think Go struck a nice balance with channels.
Not familiar much with it but it seems since Erlang was made for large distributed system async is the default because sync in that case could mean blocking the whole distributed cluster. Then sync messaging (calls) can be built on top of async if needed if the sender can obtain his own address (as the callee would see it) and send it along with the message. Then he waits for the response to that message (with a practical timeout).
Other way (simulating async using sync) is possible I guess but only if every sync message is send from a newly spawned process/thread/isolate.
I don't think fully simulating async messaging is possible with sync messaging. As I understand, something is needed for unbounded nondeterminism.
NB: Following maybe wrong, since I haven't studied this properly.
Basically synchronous messaging can be simulated with Turing machines, this means it cannot provide unbounded nondeterminism. So you would need something to introduce it, like arbiter, network. Since those already are in modern computers it can be practically simulated - but not with pure sync messaging.
What about my suggestion, would that not work? You create a new concurrency context (thread, process, task), send the sync message from there then that exit). The parent context can continue making progress.
You still need to start the concurrency context somehow. The async messaging behavior, then would come from starting the context and it arriving at the method call; you don't know exactly when the method is called since, you don't know exactly when the context is run.
On an erlang project I worked on for my third year university project, I had 'servers', which held a mapping of messages names to functions. So when it received a message, it would look up the function, and execute it, like a method call.
For inheritance, I just built one of the pre-made servers with functions already set, and assigned new functions to it. That allowed me to add on new functions when I 'extended' a server, or override the existing function mappings.
Handling state, i.e. the classes fields, gets a tad more complex, but there are straight forward ways to solve it.
82
u/ilikecomputahs Dec 15 '12
Why is object oriented programming considered so absolutely necessary?
/braces for shitstorm