I get asked periodically at work about getting started with Scala programming. This is a published answer to that question.
By far the easiest way to get started is with Activator
What is Activator?
Activator is SBT + a UI + a tool for downloading and installing templates that include tutorials. You don’t need anything else. Follow the link above to install it and get started.
What is SBT?
It’s easy to get started with SBT. There is substantial documentation available, including a book co-authored by one of the SBT committers, Josh Suereth.
Something to keep in mind as you’re getting started. There are, to my knowledge, three different syntaxes for writing build scripts with SBT. You’re liable to come across all three. The three are:
1- Straight up Scala When you see Build.scala, it’s straight up Scala code importing SBT. It’s fine, and it works, but it is not the latest form of SBT. I personally avoided looking at these examples, as I found them a little difficult to read.
2- build.sbt, with a space between each line This is a new/old style of SBT syntax. At one point in SBT evolution, the space between each line was used to delimit a line command. This was for SBT before 0.13.7. If you see this, it’s important to know that you are not looking at the latest SBT syntax.
3- build.sbt, without spaces between each line This is the latest version of SBT. 0.13.7 and later.
It’s quite common to scour github looking for examples of what you want to do. Keep these three syntaxes in mind as you do so.
There are some alternatives to using Activator.
conscript augments giter8, but I have not used this.
What should I do first?
First, install Activator and it’s dependency, the JDK.
Then find a project to download and run. Check out the templates here, and find one you like. I would recommend the amazing, interesting Spray Spark React template, because it’s really well done and has fascinating tutorial (Disclaimer, I am the author).
The templates all have their own page explaining how to get started. But for completeness, just do this:
$> activator new amazing spray-spark-react
This will spit out some instructions for you
$> cd amazing
$> activator ui
This will launch a browser and the activator ui. This will allow you to browse and edit the code, as well as view the tutorial.
It’s always nice to have a fully functioning project to get started with a new development platform. Scala has a reputation for being a little bit difficult to learn. I think this is largely unwarranted, and there are some really good tools for getting started quickly. Go forth!