views:

4167

answers:

9

I'm planning to broaden my perspectives in JVM platform, and I've got a dilemma: what should I learn first? Could you please explain, what are the advantages of Groovy, Scala and other languages for JVM? Thanks.

+28  A: 

I'd take a look at Scala first of all. James Strachan (creator of Groovy) said that if it existed already, he likely would never have created Groovy. This blog entry covers a lot of the decent features of Scala (static typing, type inference, closures, mixins etc.)

Scala has a lot of momentum behind it, and it's functional aspect means you'll not only learn a new JVM language, but a new paradigm (functional programming - assuming you've not done this before).

Brian Agnew
Well, take Jython and you'll not only learn a new JVM language and a new paradigm (yes, it has functional approach and closures), but a quite useful non-JVM language too :-)
Joonas Pulakka
I'm interested that this has received 3 downvotes. Whilst people may disagree with my sentiments, I'm not sure there's anything here to actually warrant a downvote, is there ? (i.e. anything wrong/misleading or unhelpful)
Brian Agnew
I totally agree with Brian and his very good point. He has my +1.
Pascal Thivent
While it doesn't deserve downvotes (and you have my +1), it's not a big surprise. We're all pretty protective/precious about our favorite new JVM language be it Scala/Groovy/Clojure/Jython or JRuby.
Michael
@Michael - I suspect that's the issue. But people should be advocating or voting relevant suggestions up.
Brian Agnew
I totally agree with your answer. Although it's unfair to say Scala is better than Groovy. Groovy and Grails is absolutely great in it's own way. Scala is different...
Maximilian Schweitzer
A: 

The fundamental decision is between compiled (e.g. Java, Scala...) and interpreted / dynamically compiled (e.g. Groovy, Jython...) languages. Scala is just "better Java", while the interpreted languages let you do something completely different.

If I had to choose just one in addition to Java, I would pick Jython.

Edit: From the number of parrotlike fanboy comments about how Scala "has momentum" and "is much more than better Java" and "is gateway into functional approach" it seems that Scala's marketing has been efficient. But I'd like to have pointers to successful examples of what actually has been done with it (other than Twitter) and how Scala's excellency has benefited those projects?

Joonas Pulakka
But it is said to be really slow.
folone
@folone: I don't know who said that. There are faster languages out there for sure, but whether it's a problem depends completely on what you're using it for. If you're looking for speed, learn C.
Joonas Pulakka
Scala isn't "just" a better Java - it's a gateway into a more functional approach to coding. Is it Groovy's dynamicness or its succinct language and API that are interesting? For me the succinctness is much more interesting - for comparison, doing file IO in Java versus Groovy.
hbunny
Well, Jython offers a full-fledged functional approach too, on the top of being dynamic. Of course what is important depends on what you're doing.
Joonas Pulakka
Scala is much more than "just better Java".
Jesper
I see absolutely not fundamental difference between compiled and interpreted languages. It's an implementation detail, no more. Perhaps you mean the difference between static and dynamic typing?
Michael Borgwardt
Huh? Compiled means that you have to compile it first to run it. Interpreted means that you can plug it into a running application. If this is not a fundamental difference, then what is? All right, it's an implementation detail in the sense that any language *could* be interpreted or compiled - but not every language have both implementations.
Joonas Pulakka
But Jython and JRuby *are* compiled. They have to be, to run on the JVM. There's no such thing as an interpreted language that runs on the JVM.
Daniel Roseman
@Daniel: that's silly. JVM is the Java Virtual *Machine*. It can run interpreted languages as easily as any other machine.
Daniel
@Daniel: I don't know about JRuby, but while Jython *can* be compiled, it's **not** mandatory: see http://wiki.python.org/jython/UserGuide#embedding-jython
Joonas Pulakka
+2  A: 
  • JRuby is good. It is actively developed, infact it is always up-to-date with the latest MRI. JRuby also runs Rails and many other Ruby libraries really well. You can even deploy Rails application on JVM appserver, project kenai is one running example of it. The performance is also on par with MRI Ruby.

  • Scala is also gaining momentum. Twitter is one example that uses Scala for their backend. Scala also introduces functional programming paradigm to Java programmer.

  • Jython is not there yet. It is still slower than CPython and still lacks of simple features.

  • Groovy claims to be a dynamic language that is meant to be easily picked up by Java developers, but sigh it's just not as good as other dynamic language like Ruby or Python. But the syntax should be familiar for Java programmers. But again, James's blog entry made me really sceptical about Groovy lately.

jpartogi
+7  A: 

I would say it depends on your experience and your goals. Groovy would be the easiest transition, and if you don't already know a good dynamic language this would be a good one. You can basically start with Java and then "Groovify" it, and it is the only language with a joint compiler to compile your Groovy and Java all at once. You can easily extend a Java class with Groovy, and then extend that Groovy with Java. Try that in any other JVM language. Given that Groovy was acquired by SpringSource, and how well it mixes with Java, I get the feeling its going to become the language used most alongside Java. At least in the short term. Even just as a replacement for xml configurations, it has a lot to offer.

When it comes down to it, Groovy, Jython and JRuby, JavaScript are really all the same. They have some differences in syntax, and some slight feature differences, but in the grand scheme of programming languages, it doesn't amount to much more than personal preference. Of those, if you're a Java programmer, I think Groovy is the best because it was really built to work well with Java and I think there's a real benefit to learning and using it as a tool. JRuby and Jython are really just nice so that you have access to the JVM and Java libraries from a language you prefer.

If you really want to try something new and possibly mind expanding, I would go with Scala or Clojure. Functional programming has a lot of buzz lately, especially because of the benefits in regards to concurrent programming. Both Scala and Clojure are well suited to this domain, though I think Clojure wins here. I think both languages are really well done, and you should probably learn both ;) If I were going to pick one to start with, I would say that Clojure would be simpler to learn completely (its a Lisp, so there's not much in terms of syntax), but I suppose Lisp is one of those easy to learn, difficult to master ind of things.

Scala is the opposite. It is a wealth of syntax. It has so many features, it will take you a long time to explore all of them. However, a lot of people really do see Scala as the future of the JVM. It's the only one that is statically typed. It has good integration with Java (though not as good as Groovy). It has decent IDE support, getting better all the time. And it really is a fundamentally different paradigm from Java. You will expand your brain from using it. You likely won't want to go back to Java afterwards :)

If I were going to pick just one of all of these to learn, I would go with Scala. If you just want to learn one new language now to test the waters, I would go with Groovy.

Russell Leggett
+2  A: 

A quick bang for the buck in the area of productivity would be Groovy, but I think something like Scala (or Clojure) has the most potential in terms of "expanding your horizons" as you put it.

If you haven't done functional programming before, then it will cause brain ache as you learn to think and see problems and their solutions in a new light.

hbunny
+5  A: 

I can't recommend scala highly enough. I must say that I found Python's lambda syntax (and Ruby's) unclear, whereas Scala's is particularly natural and concise:

coll.foreach(println)

There is a huge amount of thought gone into scala's library and type system and their simplicity masks some very powerful concepts (like using Option instead of returning null).

I would also say that having a statically-typed language is very useful when tool support falls behind what you expect to see from the Java world (for example, in refactoring)

oxbow_lakes
I'm also a fan of Scala, but I feel I should point out that your example of Scala's anonymous function syntax is best-case. The worst case is a little more verbose, e.g. coll.foreach( (x: String) => println("String") )
Matt R
+13  A: 

I defer comparisons between Scala, Groovy and Clojure to the answer I made to that question already.

I'll add, then, JRuby and Jython. Both of these particular compilers are not quite there yet, mostly because JVM doesn't play nice with dynamic languages, so they have to go through some hoops.

Now, Ruby and Python are definitely two of the most important dynamic languages today. While they certainly compete against each other, they are quite different by themselves, in the community and philosophy.

Python is about choosing the Right Way and sticking to it. It's particularly conscious of form, and think form and semantics should not be dissociated, the most obvious example of which is the decision to delimit blocks through identation. As long as the particular decisions taken in Python agree with you, its a language that will please people who value stability.

Ruby is about going Your Way, the most striking example of which is the eagerness with which Ruby developers extend the language and libraries, sometimes to the detriment of interoperability when using multiple libraries. Their response to this late development is also quite telling: they are working on ways to keep doing that without causing such problems. People who like to tinker may well prefer Ruby.

Python had definitely a head start -- back in '99 it already had a name to it, while Ruby was slowing making inroads as an alternative to it. Ruby would only become a strong competitor when Rails came, and Ruby on Rails took the web by storm, leaving a path of copycats (for instance, Groovy's Grails).

Both languages have very strong community and features, and the most likely factor of choice is personal, subjective preference.

Which get us back to Scala, Groovy and Clojure.

Groovy's strongest point is that its syntax is very, very close to Java, so a Java programmer can enjoy the benefits of a dynamic language almost effortlessly.

Clojure's strongest point is that it is a Lisp. It has some advanced features, such as software transactional memory, but, in the end, the fact that it is a Lisp is more likely to influence one's decision to adopt it or not.

Finally, Scala is statically typed, which puts it in an entirely different class from all others. What often makes people group it together with the others is that it is a very concise and overhead-free language, like those dynamic languages. In that sense, a Java programmer may well be more comfortable with it than Groovy, as one gets the benefits of concise programs without giving up static typing.

Daniel
+1  A: 

This link worth more than a lot of words :)

cetnar
+1  A: 

Okay, I've actually spent last nine months, playing with Groovy and Scala (in this particular order). So finally I fell in love with Scala. It's really awesome. Some thoughts on all this things:

  • Type System. Scala is statically typed. Groovy is not. As a java developer, who hasn't worked with any scripting, dynamically typed languages before Groovy, I really prefer Scala here.

  • Libs and frameworks. Groovy's grails is less complex, then Scala's Lift. It was actually hard for me to catch all those functional features in Lift, and it still is. And as I see, this trend is common for libraries and frameworks around Scala: it is hard to understand them if you don't have some functional programming background. The other side of the medal is that it is really fun and challenging.

  • IDE's. As for Eclipse platform, SpringSource supports Groovy (with grails) greatly, whereas Scala-IDE is not so perfect with Scala (if not worse). I haven't tried IDEA with Scala plugin or Netbeans though.

As a conclusion, I'd use Groovy anywhere scripting languages are used. And as for Scala, I see it at the top of best languages for enterprise needs in five years (or less).

folone