There seems to be some competition in the field that can be vaguely defined as “The next Java”(TM).
I don’t know if there will be a “next Java” to start with. Things seem to shape up in way where the JVM is our common interoperability platform and on top of it we have a an ecology of JVM based languages.
I have used Jython quite a lot but have several doubts about it, not only on the current status of Jython (lags a bit behind CPython) but I also deslike Python (when compared with the other languages dicussed here). As such I decided to evaluate the other Scala, Ruby and Groovy.
I have done a couple of small projects in Scala (A prototype DSL for modeling malaria resistance is available here) and JRuby. I am now starting with Groovy, and I think I’ve found my new love. Here I will try to explain why, among Groovy, Scala and JRuby, I have chosen Groovy. To preempt any religious war idea, I would like to say I have full respect for Scala, Ruby, which are, with Caml and Prolog among my favorite languages (for a true crusade and flame ask me for my opinion about Perl or Visual Basic 6
).
Steven Devijver suggests that Groovy is the language with more syntatic similarities with Java. I would say that, not only that, but on the semantics and everything, Groovy is the closest language to Java. And that is a good thing. The world (both in programming languages and all the rest) is never revolutionary. Revolutions, when they rarely happen, are either a disgrace or are not that much of big change below the surface. People normally prefer (for good and bad reasons) the path of least short term pain. Groovy delivers that: almost 0 cost in starting to code coming from a Java background. Most importantly Groovy does that but still delivers most of the new goodies. This is actually the cornerstone of my argument: path of least pain while delivering the good stuff (in some cases better than the competition, as we will see).
Let me start with the fundamental reasons why I dismiss JRuby (which is, nonetheless, my second option after Groovy). First, I would like to say, very honestly, that the work of the JRuby guys is nothing short of outstanding! But I have 3 problems:
- One, by definition, JRuby is based on Ruby, a language from outside the JVM. That means semantic hurdles, coupling issues between the two worlds (think, e.g., libraries)
- Most importantly (but connected with the first point): Typing. I am a bit far away from computing issues currently (I work with Malaria currently, so excuse me if I mess strong/explicit typing and such) but clearly the typing system of Ruby make like hard for IDEs (think IDEs to neded to tame those over engineered Java APIs) and automated tools around code. Debugging without explicit typing is also a pain in a big program (I actually suffered my first debug nightmare with typing systems with Caml, arguably the mother of Scala). Some might say that Scala type inference and Groovy duck typing also are problematic in this respect; while the argument might be correct both languages have mechanisms to support typical Java explicit/strong typing and as such profit from IDEs and automated analysis tools.
- Ugly perlisms. Although I have read somewhere that those might be deprecated in the future.
Ah… Scala… Mats Henricson argues that Scala is the only option because of elegance regarding multicore computing. I fundamentally disagree with his point - multicore programming is fundamental but Scala is not really a good solution, but before we get there, lets talk about other Scala issues.
Type inference. I have some experience with the “mother” of Scala, Caml. Type inference in Caml is really elegant: I don’t remember a single case of it failing and requiring the programmers’ help in discovering the type of a parameter. That is not the case with Scala, several times the compiler seems to be “lost in translation”. Some might say that this is because of JVM imposed constraints, but if that is the case then it would raise the argument of bringing a language with a foreign semantics to the JVM and the ugliness attached to the process.
My biggest peeve? Metaprogramming. I won’t give you my opinion about it because it really doesn’t exist. It is on the Scala wiki in the section “future”. I am sorry, but a 21st century language where meta programming is absent can only be called in “beta stage”. As a side note, there seems to be something lost in the ML branch of functional programming from Lisp in this regard (no introspection and such), that is a shame (How is Haskell in that respect?).
Ok, multicore computing. This is an area where I have some experience in the JVM: [Shameless plug] I invite you to have a look at my Java Web Start, Jython based, multicore aware evolutionary biology workbench LOSITAN. Furthermore I have written tutorials for the multicore paradigm and bioinformatics:
Bioinformatics, multi-core CPUs and grid computing: Introduction (1/4)
Bioinformatics, multi-core CPUs and grid computing: User perspective (2/4)
Most importantly in this context: Bioinformatics, multi-core CPUs and grid computing: developer perspective (3/4)
Mats argues that Scala Actors and immutable data types provide a simple and elegant solution to the extremely complex problem (I am calling it extremely complex, because I think it really is) of concurrent programming. Immutable data types… Does anyone believe that the hordes of existing Java developers/programmers are ready and willing to do radical conceptual jump to immutable data types? The change from C++ to Java was minor in terms of semantics, even the change from C to C++ was much less radical that a change requiring to “get rid of all variables”. How do you think the majority of programmers will react when you say: “Forget variables”? More, as Scala allows for imperative type of programming, what do you think most programmers idiom wil be: Imperative or functional? To makes things worse, in Scala a immutable is called a “val” and the mutable a “var”. Am I the only only picturing hordes of developers, with tight deadlines just swapping L’s for R’s?
I speak for myself here: in spite of having probably more experience with “immutable” languages (Prolog a lot, Caml a bit) than most developers, when I wrote Scala code, my reasoning was so tainted by “real world” imperative languages that it was really hard to write in a functional dialect. I have the background, enough free time, and the motivation to write functional code, but it was hard to get back in that mindset.
Scala only apparently solves the multi core problem. Give it to a typical developer and he will write imperative code, unless you put a functional zealot behind him (and give the said zealot a strong, resistant whip).
How to address the multicore issue? Clearly we have a problem here. A few ideas:
- In many applications there is no big need to go multicore. In some cases lets not try to solve a problem that doesn’t exist in the first place.
- Many multicore applications can survive very well with simple concurrency management. Not all applications require a PhD in concurrent programming.
- Scala and the like. For those who can and are willing to go functional, why not? I have nothing against that. My only argument is that it won’t be mainstream.
- The way of PAIN. Most developers will continue to use old languages and paradigms and SUFFER with it. Only after much suffering there will be motivation to try out new things and, say, endure the pain of learning a new paradigm. That suffering still hasn’t happen, only after this becomes a big problem, there will be interest in accepting new solutions.
- A silver bullet that can be attached to the current programming paradigm. Sometimes it happens. Don’t misunderestimate (silly Bushism intended) the power of a “Black Swan” (A reference to Taleb’s book where he discusses the impact of the unexpected important events).
To finalize, I would like to say that I am not sticking with Groovy out of being conservative. Groovy seems to beat the competition in many areas (the biggest example is metaprogramming) and strikes a very good balance between being a “small evolutionary step” and delivering the goodies.
To really finalize, a caveat: my Groovy knowledge is still limited, one of these days you might read a post where I apologize for having written this ![]()











[…] Perfect Storm » Blog Archive » Groovy/Scala/Ruby/Python on JVM Picks Groovy over the others and identifies some issues with Scala. (tags: scala) […]
Two things:
You do realize you can ask the interpreter/compiler what the types of everything are in CAML, don’t you? CAML is one of the last languages I’d expect to give you type debugging hell.
Meta-programming is little more than a poor substitute for higher-order functions IMO. But if you see a higher value than “little”, maybe you could tell us where you’ve missed it in Scala.
Greg,
Caml can be a type debugging hell, imagine this: Function fa has a bug (a typing bug), function fa, calls fb (passing a wrong parameter type) which calls fc. Now the caml interpreter will infer a certain (wrong) type for fc. Now you call fc from elsewhere, say fd, and the compiler will throw an error in fd. Notice that the error is far, far away in fa. Solution, explicit typing everywhere on the chain (which you can do in caml)… On the example above, when fc is explicitly typed then the error will be raised on the correct chain of calls. But with explicit typing we are throwing type inference away in the first place…
Regarding Scala, you can see some comments that I have made on the scala mailing lists with my needs. I would just add another point: lack of good documentation and a community that is still small - maybe the things that I need are there but I could not discover it. With groovy its a different story…
Two points:
Your argument about Scala not being suitable for multi-core development is based on one main premise: Developers who are used to imperative languages will not or can not switch to a declarative style. Certainly, I agree that some developers will never write in that way. (I had a professor in college, who always wrote in Fortran style, even in Lisp!) And I would also agree that almost everybody switching to a new language uses the style of a previously learned language. (I did this when I switched from C++ to Java). But eventually, they will learn to write better code.
If you feel that Scala does not solve the multi-core problem, then how does Groovy do? I would think it is even worse than Scala, but I now very little about Groovy, so I could well be wrong.
Jonathan,
I am not suggesting that Groovy does better in that respect (for what I know, it does not), but that is not the point here. The point is about Scala: Call me cynical but it there is mass adoption (which I doubt) the style will be mostly imperative.
I’ve done quite a bit of odd stuff with Scala recently and I haven’t really felt the need for metaprogramming in any respect. In fact, I would argue that the need for metaprogramming in static languages is virtually non-existent beyond simple data annotation (which Scala provides). Don’t get me wrong, I love metaprogramming in languages which encourage it (like Ruby), but there are “better” ways to satisfy most of its use-cases in languages like Java and Scala.
Regarding val vs var: I absolutely agree with you on this one. Scala’s designers seem to think that the whole imperative world is going to jump-ship on mutability and begin to meditate on the purity of their composed functions (it’s no coincidence that one of the features of pure-functional languages is called *higher-order* functions). With that said, I’ve found myself structuring around immutability in my Scala code without any detrimental effect on my code. I’m not ready to abandon var just yet, but that’s not what Scala is all about. It’s a hybrid language, so you use whatever works best for a given scenario.
That’s what you call a nightmare? Where all the answers are given to you? Then you’ve never had a nightmare. How would that debugging session have gone in a dynamically-typed language? If you think that’s any better it’s because you forgot CAML has an interactive mode as well, but many times it will be a whole lot worse.
Greg,
This was a SIMPLE example to illustrate a point. Sometimes a certain function causing bad typing inferences might be chained many functions up and calling many other things. That might be a nightmare going through many many functions. This is an example for illustrative purposes only, I still remember when I first got a problem like this, with caml light, circa 14 years ago. More or less 800 lines of code separated where the compiler was signaling the error and where the error really was. Me and my colleague went home 4am or so in the morning. I had a rehash of this a couple of years ago when I implemented a population genetics simulator in caml.
Of course the simpler solution is to explicit type anything in sight, but that is throwing inferred typing away. I can make my population genetics code available where this pattern is easily seen: some functions have some parameters explicitly typed: A bug was traveling through there.