Friday, February 22, 2008

Its 1997. Is there a reason to choose Java over Scala?

There is a growing buzz around the blogs (including this one) about Scala, and wondering if Scala is a better Java. I don't think the goal of Scala is to be a better java, but its easy to see how that statement is made, since Scala has a lot of features folks want in a language, yet compiles to .class files and can be used almost seamlessly in an existing java project.

I was asked why someone would choose Scala over java. I thought about it a bit, and came up with a different twist on the question.

Say it is now 1997, and Sun has made the decision that a virtual machine is the future. In this version of 1997, two proposals have been made for the new language to run on this new virtual machine. One is java (the current version) and the other is Scala (also the current version). What reasons, if any, would there be to choose Java over Scala? I asked myself this question yesterday, and still havent come up with a single reason.

Can anyone think of a reason to choose java over Scala, if you just examine the features of each language? The reason i reference 1997 in the question, is to throw out the IDE and 10 year history that java has. Imagine both languages are new to the scene and you have to choose one (and no, the choice of ruby, python, etc arent valid..i want to keep this focused on just these 2 languages). I honestly can't think of a reason I would pick java if both are starting from a clean slate. That is hard to admit for someone who has been a hardcore java fanboy for 10 years. At the same time, it is exciting to see a language like Scala gaining some momentum, as I am increasingly joining the camp of those would would like to replace all their java work with it.

NOTE: This wasnt made to start a flame war. 100% of my job is java based. I am actually hoping for some solid, in-depth, NON-FLAMING, answers to this question.

13 Comments:

At 11:41 AM, Anonymous Anonymous said...

I think a good argument could be made that the industry needed to go through Java at the time it did. Java provided a much needed intermediate step, from the bad old days of C++ and VB to a more rational software engineering ecosystem. As such, you might have had trouble recruiting people who could make the conceptual leaps involved.

Nowadays, the only downside of starting in Scala rather than Java is lack of a Java-class IDE.

 
At 11:58 AM, Blogger dserodio said...

Syntax. One of the main reasons for Java's great success circa 1997, was the similarity between Java's syntax and C++'s syntax.

Scala has many syntatic "quirks", like putting the type name after the parameter name (UML-like, but different from Java, C++, C# etc), square brackets for generics...

If Scala's syntax was closer to the "mainstream" languages, I bet it would be much more successful then it is now.

 
At 12:22 PM, Blogger Andy said...

I have my problems with Java, but the thing is that it isn't 1997. It's 2008 and Java has 10 years of libraries, frameworks, and tools. Given how long it took Java to get to where it is, I can only hope these new languages are able to leverage some of that to avoid some of the mistakes Java made along the way.

 
At 12:43 PM, Blogger Jeff C said...

Anonymous: Good point, and i totally agree with both of your statements.

Andy: You are right, it isnt 1997. The point I was trying to make was to just look at the language of the two. Java does have 10 years of frameworks, but since Scala seems to be able to use them just as Java does, I am not sure the libraries give java an advantage. The only real advantages today for Java (in my opinion) are 1) all the devs with java experience and 2) IDE support. Thats pretty much it.

 
At 12:52 PM, Blogger dserodio said...

Yeah, Eclipse (and IntelliJ IDEA) have really raised the bar for IDEs.

If I programmed in Notepad (or Vim) it'd be much easier to switch (even partially) to Scala, Groovy or similar.

 
At 1:36 PM, Anonymous Anonymous said...

What about Swing? Does Scala have any graphical / windowing capabilities? I would say that is a huge factor.

 
At 2:07 PM, Blogger dserodio said...

All Java APIs (including Swing) are accessible from Scala

 
At 4:53 PM, OpenID villane said...

dserodio: I also thought the same about Scala syntax -- that it has many quirks and that would stop adoption.
But the more I use it the more apparent it is that there are good reasons for that syntax, and actually I've come to like it. It's actually starting to get weird going back to Java (which worries me since I still get paid for coding in Java :)).
But I still sometimes start writing the type before the variable name in Scala, though :)

 
At 7:49 PM, OpenID Daniel said...

For the record, postfix typing *is* mainstream, just not in the imperative camp. Type annotations in ML and similar have always been postfix. It's really just a C thing to put types ahead of the variable.

 
At 5:44 AM, OpenID villane said...

And of course, there used to be Pascal. I'm not sure whether it was mainstream at any time, but when I started learning programming, Pascal and C were the main choices (I learned Pascal, BTW).

 
At 12:06 PM, Blogger Chris W. Hansen said...

Anything that can be done in Java can also be done in Scala and visa versa. The important distinction is that some things can be expressed more elegantly in a functional style than an imperative one (also visa versa) and Scala supports both paradigms, while Java does not. So, in your alternate 1997, I have to go with Scala, hands down.

I actually think that proposals like BGGA and the like will ensure that future versions of Java look more and more like Scala. So, instead of waiting until Java 7 or 8 is released, I have been using Scala recently and have been very pleased thus far.

About the syntactic "quirks", the only one that has irked me has been the way overloaded constructors work with subclasses, but that comes up relatively rarely anyway and there are alternatives.

 
At 5:45 PM, Blogger Anirudh Vyas said...

Scala is a good language; I haven't tried it extensively, but some of features like Function types will be there in Java 7; so i don't know ...


Regards
Vyas,Anirudh

 
At 5:47 PM, Blogger Anirudh Vyas said...

Chris,

In case you're wondering, if you really wanna try something better in functional programming paradigm, you should give Haskell a try. Its sweet.

Regards
Vyas, Anirudh

 

Post a Comment

Links to this post:

Create a Link

<< Home