views:

320

answers:

8

What is your preferred scripting language in java world (scripting language on JVM) and way? When do you prefer your scripting language over java (in what situations for example for prototyping)? Do you use it for large projects or for personal projects only?

+4  A: 

My favorite is Jython, and I use it by embedding a Jython interpreter in my Java application. It is being used in commercial projects, and it allows to easily customize the application according to the customers' needs without having to compile anything. Just send them the script, and that's it. Some customers might even customize their application themselves.

Joonas Pulakka
+3  A: 

I might prefer Scala, but I can't say, still learning. At the moment using Groovy to write small utility programs. Haven't tried even Groovy on Grails. Heard lots of good about Lift Framework for Scala as well.

Adeel Ansari
I was a Scala fanboy for a while (not intended as an insult, it's directed at myself, not you) but I found myself annoyed by its pedantry concerning types and its somewhat complex syntax. It feels like a language with too many kitchen sinks bolted on. I found Clojure to be more comfortable. Of course, everybody's mileage may vary.
Carl Smotricz
+3  A: 

JavaScript Rhino has a compelling advantage -- it is included with the JDK. That being said, later versions of Rhino than the one with Java 6 have nice features like generators, array comprehensions, and destructuring assignment.

I favor using it whenever the ceremony of handling Java exceptions clutters up the code for no real benefit. I also use it when I want to write a simple command-line script that takes advantage of Java libraries.

Steven Huwig
+3  A: 

I've successfully used Groovy in a commercial project. I prefer scripting languages because of duck typing and closures:

def results = []
def min = 5
db.select(sql) { row ->
    if (row.value > min)
        results << row;
}

Translation: Run a SQL query against the database and add all rows where the column "value" is larger than "min" to "result". Note how easily you can pass data to the inner "loop" or get results out of it. And yes, I'm aware that I could achieve the same with SQL:

def results = []
def min = 5
db.select(sql, min) { row ->
    results << row;
}

(just imagine that the String in "sql" has a "?" at the right place).

IMHO, using a DB with a language which doesn't offer rich list operations (sort, filter, transform) and closures just serves as an example how you should not do it.

I'd love to use Jython more but the work on Jython 2.5 has started only recently and Python 2.2 is just too old for my purposes.

Aaron Digulla
Not only could you achieve the same with SQL, it would be more efficient and easier to read if you did...
Steven Huwig
... and I wouldn't have a simple example that would fit into five lines and which everyone here could understand without 10 lines of explanation. Mind the intent, Sir.
Aaron Digulla
A: 

Java. Seriously. It's a powerful, easy-to-use (if a tad verbose) language that everybody knows. The integration with Java is great.

Tom Hawtin - tackline
+1  A: 

The company I work for embeds Groovy into a Java/Spring website, which is deployed on a number of sites. The scripts are stored externally of the compiled WAR file, and allow us to manipulate some of the site logic without having to roll out new WAR's to each site. So far, this approach has worked very elegantly for us.

A particularly nice feature of Groovy is that it can closely resemble Java code, which makes it very easy to port existing Java classes to it.

seanhodges
+1  A: 

How about SISC (Second Intepreter of Scheme Code)?

REF: http://sisc-scheme.org/

Bubba88
+1 for pointing this language out. Looks very cool, especially if you're a seasoned Scheme specialist unwilling to switch to Clojure.
Carl Smotricz
+4  A: 
Carl Smotricz
+1 - as Stuart Halloway has pointed out: Clojure is a better Java than Java.
Will