{ by david linsin }

September 24, 2007

Scripting with Java Interfaces

I just read a nice article at java.net about scripting support in Java. I've read various articles about the Scripting API so far, but using POJI for let's say JavaScript functions was new to me. You can take a simple Java interface like this one

public interface Time {
public void getTimeForCountry(String argCountry);
}

and basically implement it using for instance JavaScript.

function getTimeForCountry(country) {
return "Time in " + country + " is " + new Date();
}

I think this approach gives you the power of designing your application using statically typed interfaces, but at the same time keeping the flexibility of using a scripting language for implementation.

In the article mentioned above the author tries to tackle the issue of performance. He suggests using a scripting language for development phase and switching over to their byte code representation when going live. Groovy is mentioned in this regards, cause it supports compilation to Java byte code.

I don't fully agree with this. For me the power of using a scripting language in Java is it's dynamic nature: making changes on the fly without having to recompile or redeploy your application together with an easy to understand syntax. I wouldn't introduce another language just for the sake of "enhancing" development productivity, since you always introduce more complexity and clutter.

What I do agree on is that languages like Groovy and Scala, which are both compatible with the Java language, bring value in terms of expressiveness. Features like mixins or case classes in Scala give you so much power and yet the language itself is so concise and clean. I could very well think of implementing components using Scala, putting up with more complexity, but gaining more power and conciseness.

0 comments:


com_channels

  • mail(dlinsin@gmail.com)
  • jabber(dlinsin@gmail.com)
  • skype(dlinsin)

recent_postings

loading...