Hacker News new | past | comments | ask | show | jobs | submit login

Javascript is a great language, and it will never replace ruby, python, java, or any other languages mentioned.

Let's get right to the core of the problem: prototypical based inheritance is worse than class based inheritance. It's nothing like what all other languages are using, it's a pain to use and it's less powerful. That's the only language feature that is wildly inconsistent from other popular languages.

Rhino's been around for long enough that if javascript was going to be the next big language, it should be used by lots of smart hackers as a scripting language. And yet, they keep turning to Ruby and Python and concurrent functional languages. Maybe with the next version of js (which is will support classes and some other nice features), javascript will become big. Until then, I'm not holding my breath.




> it's less powerful

Actually, in some ways, JS-style prototype-based inheritance is more powerful. You can emulate class-based inheritance, but you can also use a variety of other models, such as adding in only a single specified method from another class or adding in capabilities on a per-object basis instead of per-class.

Yes it's different, and maybe it's a pain to use -- especially if what you want is for it to be language x (for some value of x) -- but I don't understand how you can justify the claim that it's less powerful.


Classes vs. prototypes is just static vs. dynamic inheritance. You'll generally have the same arguments as those between static and dynamic typing. They're both "powerful" in their own right: static code tends to be faster to run, dynamic code tends to be faster to write. Depends on which you value more in a given circumstance.


"Let's get right to the core of the problem: prototypical based inheritance is worse than class based inheritance."

Can you defend this?


When I use it, it always feels like you are forcing OO on something that would rather stay functional. I would agree it seems artifical, but then maybe its just familiarity.


In my experience, JavaScript has tremendously powerful capabilities both in terms of OO and in terms of FP, and if you can get comfortable with it, you can mix the idioms seamlessly. Using something like the Prototype library helps -- it adds power for metaprogramming as well as for more practical things like DOM and event manipulation.

Once you figure out OO idioms you like using, the main limitations are random annoyances like the lack of a clean idiom for linked lists and the fact that the JS spec doesn't require tail call optimization, so some functional idioms are going to be dog-slow.


I use Scala a bit - and it is OO/functional hybrid - it really steers you in the functional direction. I personally find it hard to reconcile OO with functional though (as in side effect free functional). I guess my personal (probably incorrect) experience with OO is all about mutability and state machines, whereas that is totally at odds with the rest of scala. So I end up not knowing what to do with the OO bit. I do like OO though, but I just can't seem to get it to fit together in my mind.


> Let's get right to the core of the problem: prototypical based inheritance is worse than class based inheritance. It's nothing like what all other languages are using, it's a pain to use and it's less powerful. That's the only language feature that is wildly inconsistent from other popular languages.

Fortunately, it's easy to build a real object system on top of Javascript's "default":

http://code.google.com/p/joose-js/

Perl is the same way. The default object system is garbage, but when you put Moose on it, it's the best of any language. (CLOS is a very close second, but it needs roles/traits!)




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: