If you're a Java programmer and you don't currently count Groovy as part of your toolbox, please go here and download it. Don't worry, I'll still be here when you get back.
This little scripting language for the VM may not be revolutionary insofar as there are others in this same niche (e.g., Jython, Beanshell, JRuby, etc.), but it has one major advantage that has kept it close to my heart: the learning curve is non-existent. I'm not saying that you'll master it from the moment you start using the console or shell, but as a Java programmer you'll be productive from the first line of code. Let me give you an example. Let's say you have this existing class:
public class Foo {
private String name;
public void sayHello() {
System.out.println("Hello "+name);
}
public void setName(String name) {
this.name = name;
}
}
From Java, calling this might look like:
Foo bar = new Foo();
bar.setName("John Smith");
bar.sayHello();
Now here's code that will run in Groovy
Foo bar = new Foo();
bar.setName("John Smith");
bar.sayHello();
I'll give you a second to compare the two. Now, this isn't the best way to write this code in Groovy, with this being a good alternative if you don't really care about typing "bar":
def bar = new Foo(name:"John Smith")
bar.sayHello()
...but the point is that from a productivity standpoint you can add a scripting language that's native to the JVM to your list of tools and start using it as soon as it's installed. Over time you will discover the more powerful features like closures and sensible collection initialization, but on day one you will be producing working code without the cognitive dissonance normally attendant on a new language, which is also a good argument to your boss as to why you should get to play with this shiny new toy.

No comments:
Post a Comment