Scala is a general purpose language that runs on the JVM (though there is a version for .NET) that maintains a large amount of interoperability with Java and has a fairly small learning curve. The programming language aims to make substantial improvements on Java, mostly by reducing verbosity and introducing a variety of functional programming elements. Because it is interoperable with Java and runs on the JVM, Java developers do not have to give up their existing work if they want to start using Scala in projects.
Scala is not a commonly used language, though some high profile projects have been done in it. I have been interested in Scala since I first heard about it a couple of years ago; unfortunately, I’ve never had time to explore the programming language in-depth. A few weeks ago, I spoke with Michael Pigg of Chariot Solutions, who has been using Scala for some time, to learn more about what it is and why developers should consider using the language.
Mr. Pigg sees three major improvements in Scala over Java:
- Increased productivity due to reduced verbosity,
- Developers can mix and match imperative and functional programming paradigms as needed, and
- Built-in functionality for parallelism and concurrency.
All three of these appeal to me. During my brief period of time with Java (2001 - 2002), I was constantly appalled by the amount of code that needed to be written to get anything done in Java. I felt like about a quarter of my code lines were actually “get something done” and the rest were boilerplate, braces, etc. I am also a long-time fan of functional programming; however, I do not feel that functional languages are great outside of certain niche uses. Parallelism and concurrency are also two areas of particular interest to me, though it seems like most developers have not found a good use for them yet.
I looked at samples of Scala code and the equivalent Java code, and I understand exactly what Mr. Pigg means. The need to write scads of boilerplate is gone in large part. In addition, the appropriate use of functional programming techniques where appropriate can save a lot of code, especially looping. This is something that I always liked about Perl, and if I wrote more algorithm-style C#, I would like it in that language too.
While talking to Mr. Pigg, it struck me that it seems like Scala is the same evolution over Java that C# has been having with itself. C# has been going down the same path, adding the same sorts of tricks to reduce verbosity (like type inference, auto properties, anonymous classes, closures, etc.), as well as adding functional programming techniques to simplify things in specific circumstances. And funny enough, when I first encountered C#, I felt that it had the same issues that Java did at the time. It definitely appears that the folks behind Scala and the C# team are thinking along the lines in terms of how to make improvements.
Based on my experiences with Java and the evolution of C#, I can see why a Java developer would definitely want to check out Scala. Because Scala runs on top of the well-supported JVM and interoperates with Java, giving it a try should not be a significant investment of time and energy for Java developers.
Keep your engineering skills up to date by signing up for TechRepublic’s free Software Engineer newsletter, delivered each Tuesday. Automatically subscribe today!