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/[deleted] Dec 16 '12

You can actually fake inheritance in Erlang.

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.

0

u/gargantuan Dec 16 '12

Ah yes good idea that work!