Last week I started a Coursera online training course about Functional programming using Scala. The course is leaded by Martin Odersky, the creator of Scala language program, so it’s a great chance to improve my little knowledge of funcional programming in general and Scala in particular.

When you start working with a new language, first thing you should do is find out the right tools that will make you feel comfortable while spending several hours learning and writing code.

I’ll summarize the steps I followed on my computer (running Mac OS X).

1. Install the interpreter

brew install scala

2. Install SBT, the build tool

SBT is for Scala what Maven is for Java. I haven’t used it in depth yet, but hopefully it’ll suck less than Maven.

brew install sbt

3. Write your first Scala code using the Scala REPL

Scala provides a built-in interpreter (Read-Evaluate-Print Loop) to write and run Scala code very easily.

You can run the Scala REPL either using sbt or scala command:

# Using SBT
juandebravo [~/bin] λ sbt console
scala>
scala> println("Hello world")
Hello world
# Using scala
juandebravo [~/bin] λ scala
scala>
scala> println("Hello world")
Hello world

4. Configure your IDE of choice. Sublime Text 2

My coworker Toni Cebrian wrote a post comparing IDEs to write Scala code. I’ll not repeat his text but write a bit about my personal choice: SublimeText2. I started using Sublime Text 2 one year and a half ago coding ruby, I stayed on that when I switched to python, and I’ll give it a try for Scala too. I starred some time ago this tweet about how to use Sublime Text 2 for Scala development, and eventually I read it :-)

It seems that the best option is to install the plugin sublime-ensime. It was a good surprise to find out that my pal @casualjim is the original author of this plugin. Sublime-ensime is a plugin that provides integration between Scala and ENSIME, the ENhanced Scala Interaction Mode for Emacs. Follow the instructions in the sublime-ensime github main page to make it work.

Some months ago I created project showing some cool Scala features, check it out in my github repository. To run it using Sublime Text 2, create a new Build system with the following configuration:

{
	"cmd": ["sbt", "test"],
	"selector": "source.scala",
	"working_dir": "${project_path}"
}

« Home