Tuesday, September 27, 2011

GroovyFX vs ScalaFX

Oh, it's on now.

My good friend and new alternative language nemesis, Stephen Chin, published a blog post last night introducing a project he's been working on called ScalaFX. A nice, easy way to write JavaFX 2.0 code in Scala.

I, of course, have been working with Jim Clarke on his GroovyFX project.  Stephen points out that his ScalaFX library creates code that is more concise and more readable than the Java equivalent.  That is undeniably true, but picking on poor Java because it is succinctness-challenged is too easy.  How about picking on a language that can defend itself with respect to conciseness, programmer productivity, and modern language features?

I give you the GroovyFX version of the Colorful Circles demo:
GroovyFX.start { primaryStage ->
  def circles
  def sg = new SceneGraphBuilder(primaryStage)

  sg.stage(title: 'GroovyFX ColorfulCircles', resizable: false, visible: true) {
    scene(width: 800, height: 600, fill: black) {
      group {
        circles = group {
          30.times {
            circle(radius: 200, fill: rgb(255, 255, 255, 0.05), 
                   stroke: rgb(255, 255, 255, 0.16),
                   strokeWidth: 4, strokeType: 'outside')
          effect boxBlur(width: 10, height: 10, iterations: 3)
      rectangle(width: 800, height: 600, blendMode: 'overlay') {
        def stops = ['#f8bd55', '#c0fe56', '#5dfbc1', '#64c2f8', 
                     '#be4af7', '#ed5fc2', '#ef504c', '#f2660f']
        fill linearGradient(start: [0f, 1f], end: [1f, 0f], stops: stops)

    parallelTransition(cycleCount: indefinite, autoReverse: true) {
      def random = new Random()
      circles.children.each { circle ->
        translateTransition(40.s, node: circle, 
                            fromX: random.nextInt(800), fromY: random.nextInt(600),
                            toX: random.nextInt(800), toY: random.nextInt(600))
Update: Stephen updated his version to make it shorter!  He even stole GroovyFX's new gradient stop syntax to do it.  That was low.  :-)  I have no choice but to respond by shortening the GroovyFX version even further.  (Thanks to Jim Clarke for the idea of using the parallelTransition in place of the timeline).

Not only is the GroovyFX version even shorter than the ScalaFX version, it is, in my humble opinion, much more readable.  By my reckoning that's GroovyFX 1, ScalaFX 0.

What will the final score be?  To find out, join Stephen and I for our JavaOne session "JavaFX 2.0 with Alternative Languages" on Wednesday, October 5 at 4:30 PM in the Hotel Nikko.  It should be a great time as Stephen and I battle it out to convince you that our language and library is the best choice for JavaFX development.

Who will be the winner?  Why, developers of course.  No matter which of the two languages you choose, you will have a great JavaFX 2.0 library to go with it!

And here is the psychedelic output of the program, which of course matches Stephen's ScalaFX version and the original Java version.
Happy JavaFX-ing and stay Groovy!


  1. ;-) Great battle. You are right, we developers will get the benefit AND JavaFX. The more different languages using JavaFX the more recognition it will get and the better it will be for the whole FX-communitiy ;-).

    Keep rocking Dean and Stephen and ...

    Me, I prefer Scala, but thats because I am into it. Others will use Groovy, some will mix it up. I love it ;-).

  2. Pfff! Static typing for the win! ;-)
    No, seriously, I chose to learn Scala a few months ago, but I still plan to learn Groovy some day... After all, I use Gradle to compile my Scala code (yes, heresy! :-D).

    I appreciate your estimation of the winner: this "competition" is healthy and will provide nice DSL, whatever the choice of language. Good work.

  3. But which one have more performance? I guess Scala and Scala one still nice to read.

  4. I doubt performance the performance of GroovyFX or ScalaFX will be much of an issue for any normal app. GroovyFX and ScalaFX simply give you an easy way to construct your scene graph. All the heavy lifting is done by the underlying JavaFX code and Prism.

  5. I downloaded GroovyFX from svn and compiled with Intellij and I did a small demo and it works just great. You are right with groovy feels very natural to do JavaFX development. Keep the great work.


  6. I'm glad to hear that GroovyFX is working well for you. Thanks for the positive feedback!

  7. I have downloaded GroovyFX and it working great for me.. Thanks!


Please Note: All comments are moderated. That's why you won't see your comment appear right away. If it's not some stupid piece of spam, it will appear soon.

Note: Only a member of this blog may post a comment.