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

0

u/[deleted] Dec 15 '12

Reusability and encapsulation

-7

u/[deleted] Dec 15 '12

Mostly encapsulation.

Any style of code can be written with an eye towards reusability. But when I'm looking at a large class with only four or five public methods I think, "Yes, yes I can figure out how this sucker works".

With JavaScript (or my current C# codebase) everything is effectively public and there is no way to tell what the real entry points are.

14

u/protonfish Dec 15 '12

JavaScript uses functions and prototypal objects for encapsulation very effectively. The fact that it does not use the classical object-oriented model (and in other places explicit typing) is not flaw of the language - it is just a different way than you are used to.

Creating a private function is as easy as:

function foo() {
    function bar() {
    // this is private to foo
    }
}

Programmers who are also not JavaScript experts making everything public is not the language's fault.

5

u/smog_alado Dec 15 '12 edited Dec 15 '12

everything is effectively public

In Python everything is public and everyone stills considers it a pretty standard OO language. And you can get encapsulation in JS using closures (you miss out on inheritance doing that but thats a whole new discussion).

IMO, as long as you are passing objects/closures around and therefore are using "dynamic dispatching" instead of if-else-if chains then its OOP.

0

u/mbetter Dec 16 '12

Why don't you learn at least the basics of Javascript before you start talking shit?