Scala is one of my primary languages which I have found useful for creating web services, large data-modeling and data processing. Below are some of my notes from my experience learning Scala.
Scala runs on the Java Virtual Machine. You’ll need to install Java first. Install Oracle Java 7, not OpenJDK or Java 6 unless you have to. I encountered a few bugs on OpenJDK but not on Oracle Java.
To install Scala, you can install it system-wide, but your build system will download the specific version of Scala for your project.
The official tutorial lists a lot of topics: (Implicit Parameters, Variances, Upper Type Bounds, etc) but I recommend not diving head deep first.
I recommend just starting with these four topics first. These topics showcase the benefits of Scala while being approachable for most programmers.
Functions as first class citizens – You can use closures unlike Java.
Collections and Collection operations – The ease of performing operations on collections makes Scala a very productive language. Learn the class hierarchy and methods
Class system – classes, objects(singleton), traits and case classes.
Pattern matching – Another great language feature in making code Scala-idiomatic.
With just these four topics, you can get started writing effective programs with Scala. Once you master these, then go onto the advanced material(type system, actors, etc)
These free books from Typesafe are a good start for the language.
The ecosystem of Scala is equally as important to learn as the language itself.
- Reddit Scala – Keep up to date quickly.
- Scala Package Release Notes – Typically a lot of recently released packages will be noted here.
- Maven Central – All major Scala(and Java) packages are published here. You can access these with any Scala build system.
- Typesafe – Founded by the Scala team, Typesafe is the Scala support team. They help companies build robust Scala environments.
- Companies using Scala – See what others are doing with Scala.
- twitter github – Twitter has a released a lot of useful Scala libs including Finagle.
- foursquare github – Foursquare
You can decide if you want to use an IDE or just plain text editors but I highly recommend using a standard build system.
- Maven with scala-maven-plugin – I found their homepage not to be as friendly but Maven is an easy build system to get started with as long as you follow the conventions.
Here’s an example pom.xml from a sample project. The main commands are to compile continuously (
mvn scala:cc), run tests (
mvn test) and package (
- SBT – The official build system supported by typesafe. I had bad experiences with this tool after trying it from version 0.7 to 0.10. It has arcane syntax and breaking changes between versions so I just stuck with Maven. Luckily the fast compiler inside SBT is available for Maven now too.
I typically use a plain text editor(VIM) with
mvn scala:cc running in the background. Sometimes I use an IDE(Intellij) if I need to use a debugger or working with a larger project. You’ll find both build systems(Maven and SBT) to work well with Eclipse and Intellij
Sublime Text – A great general text editor with scala plugins.
Eclipse – Officially supported IDE.
Intellij – I prefer Intellij’s interface.
Play – A full featured web framework similar to Ruby on Rails. Good for any general purpose web application.
Scalatra – Modeled on Ruby’s Sinatra. A very easy micro-web framework to start with. Mostly good for web services type of applications.
Lift – Used by Foursquare. I have never tried it but it is stable and well supported by a community.
Json4S – This is Scala’s primary JSON parsing package.
logback – logback is a widely used logging package.
Don’t worry about the complexity of Scala early on.
Specifically if you try to read the Scala source code, you will be perplexed initially. I would start learning by writing Scala in a traditional Ruby/Python or Java programming style first.
Learn how the JVM works.
If you wrote production Java code in the past, this will come in handy as the tuning/debugging/profiling process will be nearly the same.
All your favorite JVM tools like jstack and jvisualvm will still work.
Be forewarned of binary compatibility.
I find this to be biggest problem with the Scala environment. Packages built with an older major version(2.8.X) probably won’t work with newer versions(2.10.X).
If you find a relatively new Scala package and a well supported Java package which do the nearly same thing, I would recommend to pick the Java one for your project because the Scala package might be outdated in a few months and you won’t be able to upgrade.