JavaFX script... yawn

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. 1 - Some of the constraints have, by accident, improved many UI’s. I mentioned that before.

  2. 2 - The open web.

  3. 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)

CoffeeScript in Action

CoffeeScript in Action book cover

I'm the author. Get it from Manning.