Software Development

Why Java developers should check out Scala

The Scala programming language has three major improvements over Java. Find out what they are.

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.

J.Ja

Keep your engineering skills up to date by signing up for TechRepublic's free Software Engineer newsletter, delivered each Tuesday.

About

Justin James is the Lead Architect for Conigent.

11 comments
johnclark582
johnclark582

Hey, Nice piece of information provided . I wanted to ask a question i am from Electronics background and the company i m placed in is an IT company as for now i have no other option i have to join this company only but the main problem is this that they work on java and i don't know anything about java. I want to learn java online so saw many videos and even searched and came across http://www.wiziq.com/course/12145-the-6-week-complete-java-primer-with-training-certificate but i dont know how it is going to work for me. If anybody has taken this course please let me know..

mkelland
mkelland

We've been working with Scala from Java & .NET for about a year now at Tindr.co and it's actually been amazing. Developer productivity increase is the biggest thing that I've seen - we can create higher quality software faster using Scala than with anything else. In addition, the base quality of the software appears to be higher. The strict typing of the system catches more bugs at the compiler level and seems to create code that is easier to maintain. One of the other things that we've seen is that people seem to enjoy working in Scala more than they did in Java - it's much more actual coding and much less XML and boilerplate.

PhilippeV
PhilippeV

The fact that Scala code will run on top of Java, or Android/Dalvik VM, or .Net means it is now a great top platform to develop for (even if this requires installing a runtime support library on top of those base VMs). May be it will run too in Flash/ActiveScript VM ? The learning curve is probably not very high, but the new syntax and paradigms must first be understood. But what I like is how you transform a multithreaded design into a coordinated design with threadless "reactors" (working as fibers in a single thread) for event-driven applications. I also like the automatic management of the thread pool and immediate creation of a thread pool working on multiprocessors and multicore CPUs. Great to scale. This simple transform in Scala can certainly boost the performances. But still a step is missing for complete convergence : threads or coordinated threadless reactors should work transparently across processors or even across hosts over a network (an API allowing to connect hosts that provide execution support, plus transparent support for internal transport of the code and coordination, tuned on networking performances and availability of hosts, could allow to create a giant computing grid where the smallest devices could still connect and use the most complex applications, by downloading only the code necessary for the best local performance instead of using remote execution; a code caching mechanism, and a security model for the code and data would expose the capabilities and data just needed for the device, and the source application server could delegate execution to as many other servers or devices that can connect to it). Application: your smartphone or tablet uses the same application that is already installed and authorized on your home PC, which itself got it from Internet, before adding its own local data (not managed stritly locally but within a roamable user environment). This woudl mean the end of the concept of "local host". There would remain only a single network on which a user profile is connected (or accessible via a range of Internet or mobile routing solutions).

chanon
chanon

I have been doing a lot of Java and currently work with Python, so a lot of boilerplate, braces are gone (at least for now). But my productivity has not rocketed. of course because I am still discovering Python, tools and framework but mainly because my (lack of) productivity is not so much related to these aspects. A lot of my time is lost taking care of user interface, persistence etc So at least for enterprise db-oriented application, I don't think the language does a big difference.

Duke E Love
Duke E Love

Railo is an FOSS CFML runtime. Yeah I know... ppfft Coldfusion is dead... But CF has matured significantly over the years and has become a modern App framework. It is kind of like RoR and jQuery for Java. At its core Railo/CF is basically a big ass function and tag library for Java that takes care of 95% of a web developers chores with just a few lines of code. Imagine having the best of PHPclasses.org built into the language. And if at any time CF's built-in functions and tags cannot do what you want you can drop down into java or import Java libraries with a few lines of code. Railo and CF is all about getting stuff done.

opensas
opensas

I wouldn' t say scala has a "fairly small learning curve", unless you have a solid background in Java and, specially, in functional programming... From your article it seems like if it were a typesafe version of groovy... There are a fair ammount of complex concepts you have to learn. I would advise everyone interested in the subject to have a look at the "Scala for impatients" book... And in respect to performance, scala is (at least so far now) quite slower than java to compile (the compiler really does a lot of heavy stuff to make your life easier, indeed), but the runtime performance is almost on par with java... saludos sas

Mark Miller
Mark Miller

...I've also heard it executes slowly. I haven't programmed in it, but just what you've described here makes it sound similar to Groovy in some respects.

my_bit_bucket
my_bit_bucket

"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." You make them sound like the same thing. To use Rich Hickey's terminology, the new features of C# tend to make things *easier* but not necessarily *simpler*. Reducing verbosity can be a worthy goal, but C# has accomplished this by piling on the features, which interact with each other poorly, if at all. The C# standard is now almost as long as the C++ standard! There are many words I could use to describe the situation, but "simple" is not one of them. Compare Python, for example, which has also evolved to add properties, closures, etc., but during the same time period has removed old features which didn't pan out, or for which a better way was found, and has actually simplified its type system while making it more powerful. The downside of removing features, of course, is that you lose backwards compatibility of source code (though languages like C# can't and don't guarantee that, either, e.g., as everyone with a Tuple was reminded in 2010). The upside is that the language as a whole is genuinely simpler, and also more powerful: Python programs tend to be significantly shorter than similar C# programs. Many languages other than Python share this trait, and it's not hard to find languages that are both simple and powerful. Clojure also runs on the JVM, and also has these "three major improvements", among many others. It's also far less complex than Scala. (Then again, it doesn't use curly-braces so it's obviously a terrible language that nobody should ever use.) Based on a few years of experience writing each of Java, C#, and Python (among many other languages), and based on what I've read about Scala, I think you're absolutely correct that Scala is Java's C#. I don't think that's a good thing: everything I've heard about Scala is that it is insanely complex, especially its type system. Java might have started out as "simplicity, but no power", but someone looking to upgrade might not find "power, but no simplicity" to be very appealing, when there are several options available which offer both simplicity and power.

cbstryker
cbstryker

I wonder if Scala would be usable to write Android apps. I imagine there would need to be an Eclipse plugin or something along those lines, but this would be huge for Android developers if it can work with Android.

Justin James
Justin James

... leads me to see things like "map" as a way of making things "simpler", but the cost is that you need to force yourself to repeat the same patterns often enough that they are second nature. For someone encountering that kind of scenario rarely, I agree that it is not "easier" or even "simpler" by any means! J.Ja