11 May 2007 JavaOne – Advanced Groovy
Well after a couple of days of blue skies we’re back to good old San Francisco weather as both Mark and I have known it in the past – cold, wind and fog. So whereas a couple of days ago it seemed a shame to disappear into the underground caverns of the Moscone center, now it’s a relief to get out of the cold.
Most of the demos I’ve seen at JavaOne haven’t elicited much response from the audience. In fact, a surprising number have at-least partially failed and/or been poorly prepared. But today both Mark and I saw a demo that earned repeated applause from the audience – and it was driven entirely from the command-line.
The topic was ‘Advanced Groovy’ and the presenter was Rod Cope, CTO and founder of OpenLogic. Essentially a consultant, he claimed that OpenLogic had built the largest (and probably one of the only) production Groovy installations in the world. I found him to be an engaging speaker.
He started by giving a quick overview of the language. Whilst there wasn’t much in this for me that I didn’t already know, I did learn one thing: you can actually compile pure Java source code with Groovy, and then move the code over to Groovy on a line-by-line basis. That’s how closely related it is to the Java language.
Next he moved onto more advanced language features. I personally find that kind of thing interesting but to some people it’s probably a bit of a snore-fest. He talked about Expando Dynamic Objects, SwingBuilder (which is a Groovy version of the sort of Swing framework I mentioned in DSLs and Dynamic Languages ), Dynamic Language Extensions (although because of the limitations of the JVM, both Groovy and JRuby cannot quite match the power of language extensions in pure Ruby), and finally, the curiously-named concepts of ‘currying’ (not enough room to go into here – suffice to say that whilst it was interesting, it was a little worrying when he confessed that he’d only found it useful for testing and made a public appeal to the audience to tell him of any other uses it might have).
But things got impressive when he went to the command-line and cranked up the Groovy shell – an interactive shell for executing Groovy code. Using the shell, he typed in about 4 lines of code for an XML-RPC server and started it up. Then he cracked open another Groovy shell and wrote a client in about 3 lines. He got the client to call the server and it worked without a hitch. This earned him his first round of applause. I’ve been able to create small client-server demos using Spring and RMI, but not that small, and not with XML-RPC.
But the best was yet to come. Using an optional Groovy module that leveraged the JACOB Java-COM bridge, he was able to pop-up Excel with one line of code, create a new spreadsheet in it with another line of code, put some values into the spreadsheet with a few more lines, put in some formulas with another line, then put a graph of the results into the spreadsheet. And he did this all remotely from the Groovy shell. Excel was in one window, the Groovy shell was in the other. That was when he got his second round of applause.
Next he wrote a few lines of SwingBuilder code to popup a separate Swing frame, got Excel to export its graph to an image file, and got the frame to display the image. And for his crowning achievement, he put a button on the frame that, when pushed, inserted random values into the spreadsheet – resulting in the graph being updated – re-exported the graph as an image and redisplayed it in the Swing frame. At this stage, the audience was truly impressed and let him know it.
Now whilst this may sound like a rather peculiar and contrived demo, let me say that having sat through three days of generally unimpressive demos – usually involving some IDE labouring over the generation of a dead-simple JSF or Ajax UI – this one was remarkable if only for the fact that it was typed-in directly from the command-line and came straight out of left-field. I’ve never seen the JVM interact so easily with a Windows app – in fact, I’ve hardly ever seen them interact at all. And whilst the bulk of the magic was done by JACOB – a framework that you could just as easily use from Java – the fact that Groovy made it possible in just a couple of lines of code, without any compilation and within a shell made it all the more compelling.
So hats off to Rod Cope. His unexpected but nevertheless impressive demo has opened my eyes to a whole new range of possibilities and will have me looking into Groovy some more.
Pingback:Viva la JavaOne! | The Shine Technologies Blog
Posted at 07:35h, 01 August[…] were some exceptions to the rule (like the session Ben blogged on Groovy) but overall there was little chance to interact with the presenters. Bit of a missed […]