<< Changes for DWR | Home | Browser Wars >>

Comparing the Evolution of Java and JavaScript

Java:

Java is the most used language in the known universe. It is also a very simple* language. Some people believe that there is some scope in enabling Java to accommodate more programming styles (e.g. functional programming via closures). Others believe that being lightweight is a virtue.

JavaScript:

JavaScript is the most deployed language in the known universe. It is also a very simple* language. Some people believe that there is some scope in enabling JavaScript to accommodate more programming styles (e.g. by adding classical inheritance not just prototypal inheritance, and an optional type system). Others believe that being lightweight is a virtue.

Features:

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.

Crossroads:

The Java language is challenged by languages such as Ruby, Groovy and even Scala, all of which support closures. The majority of people that have spent serious time with these languages prefer them over Java for at least some set of problems.

The JavaScript language is challenged by Silverlight. Microsoft try to avoid saying things like "death to Ajax", but secretly (or not so secretly depending on who you talk to) they would love to control the platform once more, and Silverlight is the latest attempt at regaining control.

Features vs. Complexity:

Joel noticed that there is a big difference between good developers and bad developers. Google noticed it with it's picky hiring process. On many projects there are a few developers that do all the real work, while others just slow things down.

But much of the "keep complexity out of the language" debate is aimed at helping the people that write less code anyway.

Nail-guns and angle grinders are dangerous tools, but the building trade accepts the danger in the name of greater productivity. In software development where the difference between good and bad developers is that much greater, and where developers don't actually get physically maimed, the argument for power over simplicity is that much stronger.

In summary, extra power helps smarter developers work more quickly, but makes life harder for less smart developers. Since a small number of smarter developers generally do better work than a large number of no so smart developers, we should tend slightly toward giving developers more powerful tools.

Java:

In Java, BGGA closures enable higher-order programming. It's hard to say that the addition of closures in and of itself would cause a complexity implosion, after all, Java is virtually the only modern day programming language without them. It could be argued that the Java language can't be evolved to accommodate them, but I'm leaning towards there being a net gain by including them.

Interestingly, Google Android contains a clean room re-implementation of Java. If Sun (or the JCP) accepts closures, and if (as seems likely) Google votes against them, what will happen to Android? Will it follow how Google votes, or how Java evolves?

JavaScript:

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.


*: For some value of simple. The exact definitions of simple used in these 2 paragraphs are not necessarily the same.



Re: Comparing the Evolution of Java and JavaScript

I think its worth noting that Java already has something that is at least close to closures: anonymous inner classes (see eg. http://fishbowl.pastiche.org/2003/05/16/closures_and_java_a_tutorial). The only problem is that they aren't executed in surrounding scope, making it impossible to manipulate immutable objects or values (eg. String, int).

Apart from that, the interesting difference between closure-implementation seems to be the amount of code required to define the annoynmous function. The shortest variant I've seen is in Scala, where "i => doSomething(i)" is enough (hope I got that right). Compared to that, JavaScripts "function(i) { doSomething(i) }" syntax is rather verbose.

Another thing worth noting: The goal of ECMASCript 4 is "to make ES4 a language that is compatible with ES3 but more suitable for the development of large software systems" (http://www.ecmascript.org/es4/spec/overview.pdf). Java seems to work quite well for developing large systems - I find classical inheritance is an important tool for that.

Re: Comparing the Evolution of Java and JavaScript

Re: verbose closures in JS: we went round and round on the es4-discuss@mozilla.org list, and never came to a better form than the "expression closures" now in Firefox 3 beta:
function cube(x) x*x*x;
as shorthand for
function cube(x) { return x*x*x; }
The infix => syntax doesn't fit in JS's top-down parsing world (human and software parsers). The only gripe left is that function is seven chars longer than Unicode Greek letter Lambda ;-). Which we could appropriate, although it is a legal lexical identifier in ECMA-262 Edition 3!

/be

Re: Comparing the Evolution of Java and JavaScript

Androids JVM is called Dalvik. It is not a Java JVM! The trick is that the compiler translates Java source code into a proprietary “dex class“. (One difference: the original JVM is a stack machine, Dalvik is a register machine.) The Java libraries are from the Apache Harmony project.

Re: Comparing the Evolution of Java and JavaScript

Why are you trying to fuel the myth that Java has anything to do with Javascript? Why don't you compare erlang and C++? That's right, they don't have the same first four letters.

Re: Comparing the Evolution of Java and JavaScript

Eh? The post was talking about the *differences* between how Java and JavaScript are evolving. i.e. I'm saying that they're not the same thing. Why compare those 2 rather than erlang and c++? Because they are both undergoing changes, and there are parallels. This isn't true of erlang and c++

Re: Comparing the Evolution of Java and JavaScript

This posting makes me laugh when i remember these old java-applet-times. I think that JS is one of the reasons that google maps was so successfull even it was not a pioneer web application (in comparison to map24, etc.). interesting posting, take care, max

Re: Comparing the Evolution of Java and JavaScript

Great article! I am definitely in favor or extending JavaScript to support traditional class-based inheritance models. I don't think it will cause JavaScript to become too complex-- any JS developer worth their salt is already well-versed in at least one JS framework, most of which offer such functionality.

Add a comment Send a TrackBack