Among the benefits of Scala is that it allows one to write code for the JVM, to interface with existing Java libraries, and to do so with fewer lines of code that Java would require. In a recent interview, Alex McGuire, a developer with
Électricité de France, describes how his team has been gradually migrating to Scala in a 300,000-line mission-critical production application:
Ten years ago when we started writing the application we knew Java was a much better bet than C++. After all managing memory just shouldn't be the job of someone trying to get their head around pricing exotic options. So we jumped into Java and have been very successful because of it. However, the verbosity of Java has become a growing annoyance.
People complain about excessive use of parentheses in Lisp but Java requires so many just to keep the compiler happy. Then there is all that boiler plate you have to write. Most of the group are into languages so we had been looking at all sorts of alternatives, Lisp, Smalltalk, Pizza, Groovy and Ocaml. We were looking for something to improve our programming experience.
We tried them for small projects and Lisp was quite a good fit to our problem, however the lack of transparent interoperability with our existing codebase was an inhibiting factor. Then we came across Scala. It was just fantastic!
In the interview, McGuire describes how a group of developers with diverse backgrounds was able to move to Scala:
We are all from different backgrounds and consequently have wildly different programming experience. A couple of us had had mathematical training and Scala was just night and day when compared to Java. The rest of the team were all excellent programmers so they made the transition from Java to Scala quickly too.
As with many nascent Scala project, McGuire's team started out writing small parts of the application in Scala, and gradually extending that scope:
As we got confident we just wrote all new components in Scala. Of course there is still work to be done maintaining existing Java modules, so the transition is still ongoing, however the large majority of all new work is in Scala. I personally haven't created a new Java class in over six months. We currently have about 20k lines of Scala and a gradually shrinking base of legacy Java. 20K lines may not sound like a significant percentage of a 300K line system, but the equivalent Java code would be more like 50-60K lines. One of the really nice things about Scala is that you can mix and match it with your old Java code. You can manage risk very well...
Good programmers tend to think in terms of abstractions, and should be able to program these in any number of languages. The choice should never be 'which language do you speak', but rather 'which is best for the job'. So when we recruited we simply looked for good programmers with experience in several languages and they make the transition into Scala easily enough. We had the classical philosophical debates about what Scala can do versus other languages. The key question in the end is "What does it make easy?" You can do anything in most languages but many common things are just not easy or pretty in many of them.
Another common thread in many Scala projects is that developers tend to start out writing Java-like code in Scala, and later learning more idiomatic Scala patterns:
You can begin by writing Scala in a very Java like style.
You can leverage your Java knowledge to get into Scala. Take snippets of code in Java and move them into Scala. Just do what comes naturally using the Scala syntax then once you are comfortable and productive start introducing Scala syntax and functional programming techniques, like filtering and maps using anonymous functions etc. Things like the "for" are just so likeable that it does not take a good programmer long to grasp the fact that scala is neat and they just go looking for the features they need. The whole process can go very quickly indeed.
What is your experience incorporating new Scala code into an existing Java codebase? What do you find to be the most problematic issue starting to code enterprise applications in Scala?
It is interesting to see someone get excited about how it can make certain things easier to introduce operator overloading into a Java related language.
Back in 10 yeras ago when I was learning Java I got into it very quickly thanks to the awsomeness of JBuilder 3/4.
Now I am learning Scala and I am looking for an IDE that will make learning the API and the idiomatic language constructs easy-peasy just like JBuilder did 10 years back with Java.
> What IDE do they use for developing in Scala? > > Back in 10 yeras ago when I was learning Java I got into > it very quickly thanks to the awsomeness of JBuilder 3/4. > > > Now I am learning Scala and I am looking for an IDE that > will make learning the API and the idiomatic language > constructs easy-peasy just like JBuilder did 10 years back > with Java. > I'm not sure what *they* use, but I use IntelliJ IDEA with its Scala plugin. It works very well these days. The NetBeans plug-in is also pretty usable now. Only the Eclipse plug-in may still not be quite ready for prime time, but it has come a long way lately, so you may want to just try it and see for yourself. I haven't tried Eclipse in a while now, because I have been so satisfied with IDEA's plugin.