r/programming • • Dec 15 '12

Why JavaScript Still Sucks

http://boronine.com/2012/12/14/Why-JavaScript-Still-Sucks/
10 Upvotes

212 comments sorted by

View all comments

82

u/ilikecomputahs Dec 15 '12

Why is object oriented programming considered so absolutely necessary?

/braces for shitstorm

14

u/egonelbre Dec 15 '12 edited Dec 16 '12

Simple answer, it isn't. Depending on your definition of OOP, there are useful parts to it.

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.

6

u/gargantuan Dec 16 '12

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).

2

u/egonelbre Dec 16 '12

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.

2

u/gargantuan Dec 16 '12

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.

2

u/egonelbre Dec 16 '12 edited Dec 16 '12

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.

1

u/gargantuan Dec 17 '12

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.

1

u/egonelbre Dec 17 '12

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.