Wednesday, April 1, 2009

Why Scala?

I'm trying to catch up with blogging about the sessions I've attended this first day of the Web 2.0 Expo.  The second session I attended today was entitled, "Why Scala?" Presented by a fellow from Twitter, it was essentially a discussion on their adoption of Scala from their initial appraisal of the technology landscape through the pilot project successes to their company-wide embrace of Scala.

Despite not having any major investment in Java code, the JVM platform gave them access to the myriad Java libraries already out there, as well as the ability to do things like hydrate JSON as a JVM object and reason about it naturally within Scala.  Given that they were looking for a language with a great concurrency story, this appears to be the number one reason for choosing Scala, that it is a JVM language written by people who really understand the JVM internals.  Some of the other reasons put forth were:

  • Actor model--like Erlang the primary programming paradigm of Scala is independent workers that share no state and pass messages
  • Immutability--with built-in immutable data structures and the Actor model, Scala heavily encourages immutability, but doesn't force it, meaning you can take advantage of mutability when it is more expressive or performant
  • Type inference--yay, strong typing AND pretty code
  • First-class functions
  • Traits--not real clear on what this is, I think the Erlang/OTP equivalent would be behaviors
  • Pattern matching--this is similar to what Erlang does, but isn't limited to tuples or other terms, i.e. you can match objects
  • XML Literals & Query methods baked into the language
  • Case Classes--these sound like structs, maybe message types?

The "bad" thing about Scala is that it forces you to learn a bit more about the JVM than perhaps you were inclined to learn, and it is very complex.  There seems to be quite a community evolving around Scala, and the mainstreaam web framework is called Lift.