The ECMAScript discussion list (es-discuss) has a thread(s) running on future proposals for lambda syntax with several hundred posts. A similar thread on class syntax has, by comparison, gone largely ignored.
Some others have noted the potential significance of this. Does it demonstrate a trend in JavaScript? Is it indicative of where programming languages in general are headed?
As Guy Steele has put it:
A closure is an object that supports exactly one method: “apply”.
On the other hand, there’s this, usually attributed to Norman Adams:
Objects are a poor man’s closures.
Still, there really isn’t that much distance from one to the other… granted, that is relative to context.
From my point of view, classical OO has sometimes trended towards being overbearing, particularly for UI development. This is probably why everybody is excited about finding a more elegant lambda syntax for JavaScript and less interested in class syntax, which simultaneously feels more like bookkeeping and also is likely to have a mental association with an heavy-feeling ontology that many JavaScript coders would want to avoid.
Sun Microsystems have just announced the 1.0 version of JavaFX, one of the main components being JavaFX Script.
Let me get this straight. After twelve years Sun have finally admitted that writing UI’s in Swing blows goats and their solution is to release something that lets you create a swing UI using code that borrows heavily from JavaScript.
What’s it got? First-class functions, declarative syntax, list-comprehensions…
I’m going to repeat the name because I think it bears repeating. JavaFX Script. I guess the only name bad enough was already taken so they threw an FX in the middle.
If it weren’t for my horse… I wouldn’t have spent that year in college.
Here’s a JavaFX Script code sample (excuse the code formatter from getting confused with the indenting):
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.shape.Rectangle;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
Stage {
title: "Declaring Is Easy!"
width: 249
height: 251
visible: true
scene: Scene {
content: [
Rectangle {
x: 45
y: 35
width: 150
height: 150
arcWidth: 15
arcHeight: 15
fill: Color.GREEN
},
Circle {
centerX: 118
centerY: 110
radius: 83
fill: Color.WHITE
stroke: Color.RED
}
]
}
}
Looking at it, I don’t think I need to talk about where the inspiration for that comes from. Still… haven’t the GWT proponents been telling everybody for a long time that scripting languages are evil? Will GWT one day allow people to write JavaFX Script and have it compile to JavaScript? I don’t know and honestly I don’t care.
JavaScript is far from perfect but I think the current Ajax “stack” works for (at least) three reasons:
1 - Some of the constraints have, by accident, improved many UI’s. I mentioned that before.
2 - The open web.
3 - JavaScript actually has some features that are really good for creating UI’s. Homoiconicity (to some degree), lambda and a prototypal object oriented system.
JavaScript won’t last forever but I haven’t seen anything yet that is better on those three points.
Update: I notice some people have come here looking for some demistification of this JavaFX error:
com.sun.javafx.runtime.AssignToBoundException: Cannot assign to bound variable
I can’t help you. Hey, at least you’re not looking at this compile error huh?
Expected type int * int -> int, got type int * (int -> int)
There is a short text written by Poul Anderson entitled Uncleftish Beholding which shows, to some extent, what English would have looked like in the absence of loanwords. It’s interesting to see the number of phrasings that somebody speaking English now would find awkward. English is something of a mixed-breed.
If we multiply the number of language speakers by the number of documents on the web in that language then English is far-and-away the winner in those popularity rankings. I don’t know how important that is but I don’t think English is emerging as the single human language of the web.
How about programming languages? Peter Van Roy thinks that there is evidence that one true programming language is emerging. Some disagree. Esperanto anyone?
Programming languages have something resembling native speakers at least from a “how many users do we have” aspect because, as Yegge points out, most programmers only know one language. In other words, secondary languages are rare… at least for a substantial proportion of the community.
There are plenty of programmers who know how to do the same thing in several languages and try to impose that where they can. JavaScript consistently fell victim to that where people were constantly conceiving ways of doing things that didn’t suit the language. Many people did that when they moved from a training in Java to JavaScript, jumping through hoops to get JavaScript to work like Java because, you know, it looks like it can.
There’s a difference between trying to impose unsuitable syntactic sugar on a language (classes in JavaScript) and liberating the language by demonstrating how patterns from other languages might translate more naturally (Crockford’s module pattern.) It’s good to bring ideas and techniques to a language, not so good to try hammering in conventions.
Of course, programming languages are not like-for-like comparable with human languages. Still, in the way that it has taken influence from other languages - for better or worse - JavaScript is kinda like English.
Guy Steele talks about growing a language (video, pdf) indicating a desire to make a language flexible enough so that the people using it can build on the language provided. The programming language provides the rules - and hence limitations - around which programs can be created. The things people do in a programming language creates the dialogue.
Java has been successful on that level at least partly because it makes it easy for those one language people to create a dialogue or use an existing dialogue.
The thing is, a programming language can be restrictive in a way that a human language typically can not.
Programming languages are used by world builders and the type of language determines the effectiveness with which people can construct universes. Programming languages have philosophical ramifications because the construction of the programming language impacts on the types of dialogue that can happen. A human working in the regular world can invent new rules of discourse and moreover may actually invent a new language (with words or symbols) with which to describe or talk about the world.
The can be achieved in a programming language but the restrictiveness of a programming language can make constructing a new domain-specific language difficult enough that it’s almost never attempted in that language. On the JVM the rigidness of Java and an understandable resilience to change looks like it will lead to increased popularity of new languages running on the JVM at the expense of the Java programming language. As the language of discourse, Java looks like it will soon fade instead of grow.
Languages need to evolve, JavaScript managed to do that mostly by accident and in a different sense to that in which Java grew. The point though is that if JavaScript had not been able to grow at all then despite any luck it would probably now be dead.
Still, as Eich and Crockford both say, popularity doesn’t usually have much to do with the design of the language except perhaps where the design seems familiar… though familiarity itself is a double-edged sword.
In the end though JavaScript like all languages needs to evolve or die… with care.
An infinitely flexible programming language would be infinitely extensible and, most likely, infinitely useless. On the other hand, a language too heavy on restrictions will be useful… but for a sufficiently small problem set that it too would ultimately be useless.
The growth of a language really happens in the community.
Just like HTML, many of the programming languages already in existence today are trying to evolve inside the constraints of standards committees… occasionally this may prove midly successful but I think the best you can hope for when doing that is a Bonsai.