Wednesday, December 19th, 2007

Comparing the evolution of Java and JavaScript

Category: Articles, Java, JavaScript

Java and JavaScript share the first four letters of their name, and have an entangled past. Joe Walker has an interesting little take on the evolution of the languages that shows some mirror images such as:

It’s interesting that the current simple version of JavaScript already has the features (i.e. closures) that people want to keep out of Java otherwise it will become too complex, and that Java already has some of the features (i.e. classical inheritance) that people want to keep out of JavaScript, otherwise it will become to complex.

And some thoughts on JS2:

With JavaScript, people see a neat, compact language and fear it turning into Java. The good news is that it won’t fully turn into Java because JavaScript already has closures and no one thinks they should be taken out ;-) The danger of the “features over complexity” argument, is that it can be applied indiscriminately, creating a monster, and the fear is that JavaScript will become a monster.

I’m gradually coming round to the opinion that many of the changes proposed to JavaScript actually reduce complexity. There are nearly as many frameworks that add classical inheritance to JavaScript as there are Ajax frameworks. Having one solution that we can all agree on can’t be a bad thing even if you prefer prototypal inheritance.

Posted by Dion Almaer at 7:46 am
8 Comments

+++--
3.7 rating from 21 votes

8 Comments »

Comments feed TrackBack URI

Excellent post!

Comment by dcrec1 — December 19, 2007

Ya know I’m watching AS developers move from AS2 to AS3 which from what I gather is going to be somewhat akin to moving to Javscript 2. To be honest, I can’t wait. I’ve watched an endless amount of bungled impossible to follow code suddenly become legible, reusable, and easy to debug. Yes in AS2 simple things were easier to do, just as they are in our current JS world but adding some structure made the really hard things a lot easier.

Comment by vance Dubberly — December 19, 2007

While reading this post and questioning myself the evolution of JS, I am wondering if JS needs a more standard library like Java (a CPAN web site ?). Let me give an example. AFAIK GWT translates java.util package classes into JS. OK, the compiler could optimize it while translating only needed classes. But why not having a more or less standard JS library published on a Google high-speed web site so that the compiler could rely on it and the browsers could download it once for all web sites using this standard library ?

Comment by dmdevito — December 19, 2007

It often seems people read the first four letters and skip the rest of the name. It is a scripting language. There’s no shortage of complex languages and tools for the uber-geeks, but there’s also a need for simple scripting. And given the current disparity between browser implementations, do you think increasing the complexity of Javascript would make it more or less reliable, cross-browser? We shouldn’t even need all these frameworks and libraries. It’s just another layer of code and a whole new “language” to learn, in addition to Javascript. Fix the basics before you worry about expanding the scope.

Comment by McLars — December 19, 2007

dmdevito: a great idea, often suggested and discussed, even in the hearing of Google folks in the open source group there.

McLars: the disparity between browsers is mainly outside of JS — and where JS disparities hurt, you-know-who is the most behind (hint: who just patched JScript’s DLL for IE6).

Platform disparities are no excuse for halting the evolution of the web standards, including JS. It’s not as if we haven’t had years for the weaker JS implementations (never mind CSS and DOM) to catch up. Look to competitive pressure, or lack of it, to explain progress or stagnation.

/be

Comment by Brendan Eich — December 19, 2007

I agree that browser disparities (deficiencies?) should not halt JS evolution. The question is in which direction JS should be evolving, more complex or simpler. I think the recent explosion in frameworks/libraries indicates that people want simpler interfaces. Simple does not exclude greater power. For example, when you can select a whole group of elements with just a $() or $$() statement, that saves a ton of work and makes the code easiert to read and maintain. I’m all for making that sort of power native to JS. I’m just against making it harder to learn and use day-to-day. My worst nightmare would be requiring people to follow a complicated class structure just to pop up an alert. Again, there are plenty of industrial-strength, fully-compiled languages out there. Maybe more work needs to be done to get those implemented better on the browser. But JS is the only thing we have for low-level, simple scripting tasks. You can make it more powerful, yes, but please don’t turn it into Java.

Comment by McLars — December 20, 2007

Of course JS is not turning into Java, Joe spoke to that.

Here’s the thing about your very example: alert is a function object, right? Wrong, in IE — it’s a “host object”, an instance of a “class” you can’t make or extend. It has no apply or call method delegated to Function.prototype.

Give the ES4 evolutionary programming tutorial a read if you haven’t yet. Nothing like Java — way better ;-).

/be

Comment by Brendan Eich — December 20, 2007

In case it wasn’t clear, my point about IE alert was not that it is a good example of classes — but it does show they intrude into JS already. There are great examples where you do want a hardened little instance that can be efficiently created by the millions, can’t be tampered with at all, can be used as an unforgeable capability, etc. Classes as conceived in JS2 have their uses.

/be

Comment by Brendan Eich — December 20, 2007

Leave a comment

You must be logged in to post a comment.