Scala: Move Forward

Pere Villega published on
5 min, 870 words

Categories: scala

Soon Java 7 will be released. A bit delayed, yes, but it’s here. Even so the question lingers: is it enough? I believe the answer nowadays is NO, but of course this is an open discussion in which each developer will have a different (and valid) opinion as per each one’s background. Let’s give some arguments for the no, then. Let’s talk about Scala.

Why Scala?

You may be wondering why should you learn a new language. If you want to be the average run-of-the-mill developer, no need to. But by learning new languages you improve your skills due to the exposure to new methodologies and idioms. If you’ve read The Pragmatic Programmer you know what I mean.

So, why Scala? Because:

  • with Scala you will enter the world of functional programming, without leaving the comfort of Object Oriented development. Functional programming helps scalability and testability. Nowadays, with the rise of multicore processors, using a language that facilitates multithreading by removing the need of locks and threads is a huge win.
  • Scala syntax and libraries reduce the lines of code you need to write. And LOC have a direct relation with bugs: less lines, less bugs.
  • Scala runs in the JVM, and it compiles to the same bytecode as Java. This means you can mix Java and Scala code in a program, giving you access to the vast number of existing Java libraries.
  • Scala removes some of the issues with Java. For example, no more need of Guava collections, Scala gives you what you need.

With great web frameworks like Play using Scala for web development, good IDE support (like Eclipse or IntelliJ) and knowing you won’t leave the JVM, there are no real excuses to not start learning Scala. Besides laziness, that is.

But that’s for geeks, no one uses it

Not quite true. Yes, early adopters of Scala were geeks, as any early adopter usually is. But nowadays Scala is widely used, and its adoption is growing. You may not see it in “traditional” companies like Accenture. But you know Twitter? They use Scala. The Guardian? Scala. LinkedIn? Scala. FourSquare. Nature. Well, check by yourself.

Ok, but how to start?

First, get your hands on a copy of Programming in Scala. Read it. And then start coding using Scala as if you coded in Java, don’t worry about the new stuff. Just code. Check Stack Overflow when in doubt. Read other people’s code. As time goes you will find better ways to use the new constructs the language provides, and after a few weeks you will fall into “Scala mode”.

Recently I was in a Scala talk organised by TypeSafe, the company behind Scala. They mentioned that (in their experience) people starts getting as productive in Scala as in Java after using the language for 4-6 weeks.

The official Scala site can help you a bit more.

What does Scala give me?

I won’t list all of Scala capabilities, there is a book you should have bought already for that ;) But if you are curious, some of the features that make Scala great:

  • Closures: Scala supports closures. In Scala a function is a 1st-level construct and as such it can be assigned, passed as parameter, etc.
  • Currying
  • Traits, a type of Mixin that makes composition much more powerful than simple Interfaces in Java
  • Case classes, which along the built-in pattern matching provides a very flexible tool for your algorithms
  • XML as part of the language (XML as literal)
  • Powerful syntax that allows you to define operators with names like +, perfect to create DSL
  • Parallel Collections, which you can use as normal collections but behind the scenes break themselves automatically into pieces to take advantage of multiple processors for certain operations (like map, filter, etc).

And some more.

With Scala you can do everything you can do in Java. With less code, less effort, less bugs. And you can do some things Java won’t be able to do in the near future.

To sum it up

I believe Java 7 is not enough. A good step, but not enough. And the reason is that you can use Scala. Java needs to change too much to catch up, even more with the bureaucracy associated to Java processes, and in the meantime Scala will keep evolving.

The Java king is dead, long live the Scala king!