Scala is both a functional programming language and an object-oriented programming language. As a Java programmer, you’ll be comfortable with the object-oriented definition: Scala has classes, objects, inheritance, composition, polymorphism — all the things you’re used to in Java.
In fact, Scala goes somewhat further than Java. There are no “non”-objects. Everything is an object, so there are no primitive types like int
and no static methods or fields. Functions are objects and even values are objects.
Scala can be accurately described as a functional programming language because it meets some fairly formal criteria. For example, it allows you both to define pure functions and use higher-order functions.
Pure functions aren’t associated with objects, and work without side effects. A key concern in Scala programming is avoiding mutation. There’s even a keyword to define a fixed variable, a little like Java’s final
: val
.
Pure functions should operate by transformation rather than mutation. That is to say, a pure function should take arguments and return results but not modify the environment it operates in. This purity of function is what enables referential transparency.
Functional languages should treat functions as first-class citizens. This means they support higher-order functions: functions that take functions as arguments or return functions and allow functions to be stored for later execution. This is a powerful technique in functional programming.
Scala started life in 2003 as a research project at EPFL in Switzerland. The project was headed by Martin Odersky, who’d previously worked on Java generics and the Java compiler for Sun Microsystems.
It’s quite rare for an academic language to cross over into industry, but Odersky and others launched Typesafe Inc., a commercial enterprise built around Scala. Since then, Scala has moved into the mainstream as a development language.
Scala offers a more concise syntax than Java but runs on the JVM. Running on the JVM should (in theory) mean an easy migration to production environments; if you already have the Oracle JVM installed in your production environment, it makes no difference if the bytecode was generated from the Java or Scala compiler.
It also means that Scala has Java interoperability built in, which in turn means that Scala can use any Java library. One of Java’s strengths over its competitors was always the huge number of open source libraries and tools available. These are pretty much all available to Scala too. The Scala community has that same open source mentality, and so there’s a growing number of excellent Scala libraries out there.
Scala has definitely moved into the mainstream as a popular language. It has been adopted by lots of big companies including Twitter, eBay, Yahoo, HSBC, UBS, and Morgan Stanley, and it’s unlikely to fall out of favour anytime soon. If you’re nervous about using it in production, don’t be; it’s backed by an international organisation and regularly scores well in popularity indexes.
The tooling is still behind Java though. Powerful IDEs like IntelliJ’s IDEA and Eclipse make refactoring Java code straightforward but aren’t quite there yet for Scala. The same is true of compile times: Scala is a lot slower to compile than Java. These things will improve over time, and on balance, they’re not the biggest hindrances I encounter when developing.