technicalpickles

Open Source ProjectsCode that Might be Useful to You

Talks I've GivenOn Technologies and Ideas

ThoughtsWhere I Sometimes Write Things

Resume If You Believe In Those

Follow Me On

GitHubIf coding is your thing

TwitterIf you tweet

Java gets Groovier


This news is a bit belated by a few days but.... over the weekend, I spent some time getting the recently released Groovy 1.0 into the tree.

In case you hadn't heard about it, Groovy is, among other things, a dynamic language that runs on the the Java VM. Some interesting data points about it:

  • It's dynamic, for reals.
  • It's about 98% syntax compatible with Java code (I made that number up, but really, it's pretty durn close).
  • Java bytecode gets generated at runtime, no need to compile.
  • Groovy can generate Java bytecode to your typical .class files

A consequence of these points is that you can easily migrate from Java to Groovy, and have your project running exactly as it was. Then slowly, you can get into the swing of things, and take advantage of everything that Groovy has to offer as you get the hang of it.

One fear I've noticed of Java developers of jumping into a more dynamic language like python or ruby is late binding. You can't really be sure the type of your objects until runtime. Sure, you can read the documentation (assuming it's up to date) or peek at the code to be sure. With Java, binding occurs at compile time, so you can be sure that foo method expects a Bar, or that Bar has the aieeeee() method. I suspect some of this comes from defensive coding, where you become concerned about how your code will be (ab)used by others.

To combat this, a coworker and I have this idea... You use Java to define interfaces for the, uh, interfaces you care about. You can then use Groovy to implement these interfaces. By doing this, you get the best of both worlds: clients of your code get their strongly typed interface, and you get to do implementations with a more expressive syntax.

Overall, I've been pretty impressed with Groovy so far. Granted, I haven't used it as deeply as possible yet, but it certainly has a lot of potential.

In case any of this sounds interesting, here's some resources:

And in other Java dynamicism news, I've added the freshly minted JRuby 0.9.2 to the tree this past weekend as well. I haven't played with it yet, so I can't speak much on its behalf other than it's an implementation of Ruby written on the Java VM. Perhaps that can be the topic for a future blog post.

comments powered by Disqus