Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I think that you've missed the fact that we're discussing OO techniques and approaches here, rather than the overall usability of JavaScript.

The software I mentioned includes JavaScript written in exchange for money, for clients, facing deadlines, in addition to open source JavaScript projects that may not face such constraints.

In such code, we often see prototype-based OO not living up to the hype, and not being suitable for real-world work. Due to these failings, we see many, many developers resort to implementing some limited subset or variant of class-based OO using the functionality that JavaScript does offer. The fact that we see this going on time and time again, involving many different developers, all across the world, over the course of many years should tell us something. I think that "something" is that class-based OO is inherently superior to prototype-based OO for the types of problems typically encountered when developing practical software.

Besides, C is the widest-deployed platform in the world. Add in C++, and their share of the market is absolutely huge. Basically every JavaScript implementation today is implemented using one or both of them. The major browsers embedding those JavaScript implementations are implemented in one or both. The operating systems the browsers are running on are implemented in one or both. The servers they're accessing are running operating systems, web servers, database servers, programming language implementations and applications written in C and/or C++. All of this is linked together using various networking devices running code written in C or C++. So every single line of JavaScript code that's executed depends on a stunningly huge amount of C and C++ code also being executed.



I will omit language war you both (parent and grandparent) seem to like waging and I'll go straight to the point.

Which is that OO based on prototypes is strictly more powerful than popular class based ones. Which is proven by the very fact you mention: people are writing class-based OO implementations in JavaScript with easy, one can create such an implementation in under 100 LOC. So if you think that "superiority" is determined by expressive power, then (popular) class based OO sucks balls in this comparison :)

I'm including the 'popular' qualification because thinking about class based object orientation in terms of C++ and Java is rather limited. If take a look at Smalltalk you'll see wonders like #become:. Ruby has implemented substantial subset of what Smalltalk provides and Python, although through really ugly hacks, is still able to replicate prototype-ness of JS.

This hints us to the real problem I think you missed, I mean age old difference between static and dynamic typing. Things like Google's Closure Compiler seem to suggest that static typing is desirable in the large projects. And while JITing can alleviate most of the performance problems, maintenance still remains to be a pain in the ass. This same thing applies to class and prototype based OO - while more expressive for the most part, prototypes are not as maintenance friendly as classes are. All sorts of tools, when working with classes, can provide you autocompletion, for example - it's much, much harder with prototypes, which can change at any moment.

So, to summarize, I think you blame the right thing but for incorrect reason. Prototype based OO is "better" than class based in terms of expressiveness, but "worse" in terms of maintenance (for now at least). As everything, both techniques have a place in programming and it's just stupid to bash one or the other.


I don't think the assertion that JavaScript's prototype-based OO is more expressive because it lets you fake partial implementations of class-based OO with relative ease is true.

Now, if we could reliably implement class-based OO systems comparable to, or even better than, those found in Java, C#, C++, Python, Ruby, and Smalltalk, for example, then maybe we could say prototype-based OO is more expressive.

However, all we end up with are multiple half-assed (for a lack of a better term) approaches, each of them critically incomplete in one way or another, and often incompatible with one another, too. This creates the integration and maintenance headaches that should be more than apparent to anyone who has worked on any sizable JavaScript code base.

In fact, I think we see the opposite in reality. It's much more effective to implement prototype-based OO systems using class-based OO languages. We see exactly this with the major JavaScript implementations (i.e., prototype-based OO systems) today being written in C++.

So prototype-based OO fails to deliver both in terms of expressiveness and maintainability. It is just a worse technique, when considering the facts. Trying to pretend it's good at things it clearly isn't good at doesn't make much sense to me.

And there's no "language war". C and C++ do the vast bulk of real work today. No other languages today can compare to them, and the ones that try still depend very heavily on one or both.


> So prototype-based OO fails to deliver both in terms of expressiveness and maintainability. It is just a worse technique, when considering the facts. Trying to pretend it's good at things it clearly isn't good at doesn't make much sense to me.

You are focusing too much on prototype OO.

The models offered by Smalltalk, Beta, CLOS, Haskell and quite a few others are different approaches to the classical model known to the average developer.

This is the main problem in the "offshore everything model" that looks for cheap dumb developers able to work like cogs and not required to think.

> And there's no "language war". C and C++ do the vast bulk of real work today. No other languages today can compare to them, and the ones that try still depend very heavily on one or both.

When I started developing (1986), C was just another language that most people did not care about. In fact I only cared to write some C code around 1993.

The current situation came to be due to UNIX's influence in the enterprise and the fact that any developer worth his salary isn't not going to rewrite the full stack from zero.

It has nothing to do with their suitability for OO development.


I focus on JavaScript and its attempt at prototype-based OO because there's a huge amount of such code that already exists, and more is being written each day. It poses practical problems affecting many developers today.

While Smalltalk, BETA, CLOS, Haskell and other languages do have their own approaches, we really don't see them being used anywhere near as much as JavaScript, C++ or Java are. Realistically, Haskell is seen rarely outside of academia, aside from some very isolated projects. C++, and then Java, put an end to any real momentum that Smalltalk had gained during the 1980s and 1990s. BETA and Common Lisp see very little usage these days, too. They are pretty much irrelevant in a discussion of applied software development.

I wouldn't attribute C's success and C++'s success purely to UNIX or enterprise users. In fact, many of the most significant users are open source projects. They're successful because what they offer is what developers need. Flexibility, performance, portability and in C++'s case, sensible and practical object-orientation. People go out of their way to use C and C++, even when it isn't as practical (such as under Windows and various embedded platforms). This is quite different from people using JavaScript, which is used mainly because it's the only practical option available for browser-based scripting.


> C and C++ do the vast bulk of real work today.

That's true, but I just have to ask: so what? I, for one, don't subscribe to the theory that popularity equals quality. Although both C and C++ are immensely popular in terms of code written in them that doesn't mean they're the last word in language design.

> No other languages today can compare to them, and the ones that try still depend very heavily on one or both.

I don't understand what you mean by "compare to them". If you mean in terms of features - sure there are languages more advanced. If you mean in terms of popularity then I can only say I find such comparisons meaningless.

> Now, if we could reliably implement class-based OO systems comparable to, > or even better than, those found in Java, C#, C++, Python, Ruby, and Smalltalk, > for example, then maybe we could say prototype-based OO is more expressive.

We can do this (modulo "reliably", which I don't understand what you mean by) and that's the problem. You yourself explain this:

> However, all we end up with are multiple half-assed

That's exactly the case. Java, C++, Python and Ruby are extremely incompatible with each other. No wonder that JS implementations of ideas taken from those languages are still incompatible - although less so than originals between themselves. It's also not that strange that they are incomplete - given that everything you'd like to do in class-based system you can do with prototypes there is simply no need for frameworks being complete.

Can you post a few examples of what is possible in Java and not possible in JavaScript?

Also remember that language designers can alter syntax to better support their systems, so we need to exclude syntax from comparison.

> It's much more effective to implement prototype-based OO systems using class-based OO languages.

I don't know if it's impossible, but your examples are flawed. Of course you can write any language in any language, like JS VMs are. But that's completely different matter, I was talking about using the language itself in a prototype based manner. I suspect that, due to static and low-level nature of classes in C++ it's completely, utterly impossible to replicate JS object system inside C++. That you can write interpreter that implements this system is obvious and not interesting at all.

As a counter example, in Python you could, with careful use of metaclasses and implementation details of classes and objects create objects whose methods lookup order and semantics of would be the same or close to those of prototype based JS - in the language itself.

=======

Your arguments fail to prove that prototype based-ness somehow fails. It does not, in itself, fail in any way. As I wrote above, show what can be done with classes (single inheritance model) that cannot be replicated using JS or better IO prototype semantics - that would be convincing. The fact that JavaScript development is a mess - I won't deny it - proves nothing about prototypes and only a bit about JS.

By the way, have you tried Haskell, OCaml or F# and Erlang?




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

Search: