RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


JavaFX Script in Action: Lacking for RIA, Promising for Mobile : Page 3

How does the new JavaFX Script language fit with existing Swing and Java2D UI development? An experienced Java UI developer breaks down the good, the bad, and the ugly.

The Bad and the Ugly
The shortcomings of JavaFX Script are impossible to ignore.

Lacking Development Tools
Development tools for JavaFX are practically non-existent. Very simple plugins for NetBeans and Eclipse (good to see Sun actually developing for Eclipse) are available, but they are quite limited. The NetBeans version I tested basically offers nothing more than some very basic syntax highlighting, weak code completion, and often-reported errors in code that compiled and ran fine. The plugin for NetBeans 6.0 crashed or locked any time I tried to paste some more complex JavaFX Script code into it from an existing file (especially if it had any syntax errors). A recently posted build offers a split-screen preview, but it is far from the power and ease of the Matisse GUI Builder for Swing (not to mention competing Microsoft tools).

Frankly speaking, the state of JavaFX tooling is plain embarrassing. I hope Sun realizes that without proper development tools JavaFX Script's chances of success basically are zero. They should take a look at Microsoft Expression Blend (see a sample screenshot here) and ensure both NetBeans and Eclipse plugins are at a comparable level of functionality.

Best Features of Java Are Missing
Used to documenting your code using Javadoc? You'll find no signs of it anywhere in JavaFX Script. Want to create a JPA entity or EJB 3.0 out of a JavaFX Script class? Forget it; JavaFX Script does not support annotations. Want to use generics to retrieve a result from a Java method that returns a typed collection of objects? You can't with JavaFX Script, because it does not understand Java generics. Want to create a panel in JavaFX Script and use it in an existing Swing application? Once again, it's not possible (or at least very hard to accomplish) in JavaFX Script. Since it's a scripting language that is not compiled, compiled Java code cannot access any of its properties. However, the JavaFX team has started working on a compiler project, which I hope will alleviate these integration issues and allow the best features of both languages to be used seamlessly within the same application.

Questionable Language Design Choices
I understand that JavaFX Script is supposed to be a scripting language and hence more dynamic than Java, but some aspects of its design left me somewhat perplexed. At the top of the list is the lack of constructors (yes, you heard that right). That means in JavaFX Script you cannot reliably write any class relying on constructor parameters to initialize properly.

Instead it offers "creation triggers," which are defined outside of the actual class like this:

class X {
              attribute nums: Number*;

trigger on new X {
	insert [3,4] into this.nums;

Similar "update" and "delete" triggers are available for any type of collection, and you define them outside of the actual class as well. I really dislike this whole approach. It's bound to lead to horrendous spaghetti code in any larger-sized JavaFX Script project (imagine multiple places defining their own creation triggers on the same class).

The second issue that irks me is that JavaFX Script allows you to write stand-alone functions like this:

function z(a,b) {
           var x = a + b;
           var y = a - b;
           return sq(x) / sq (y);

As you can see, this function is not part of a class but rather just an element on its own. I've seen enough horrendous JavaScript code to know any language should avoid this feature. Also, I have some very bad memories of an old PowerBuilder project I worked on quite a few years ago. The original developers wrote the entire application framework as a collection of stand-alone global functions instead of providing a proper object-oriented API. The ability to do the same in JavaFX Script will lead to some very hard-to-maintain code down the road.

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date