Resources

Scala

Scala is installed Linux workstations in the CS Computer lab in 301 MLH. You can access those workstations remotely from your own computer.

Scala Editors

We recommend Sublime Text 3 with SublimeREPL. However, most editors provide syntax highlighting for Scala. Some also provide other useful features such as code completion and so on. Industrial strength Scala IDEs are probably overkill for this class.

Simple Build Tool

This tool will be useful later in the course, for the project or some more substantial programming assignments. SBT can be used from a terminal window in Linux or MacOs and from a command window in Microsoft Windows.

Creating a simple project with SBT

  1. First create a base directory to store the contents of your project, for example my_project.

  2. Add all source files you wish to include in your project to the directory my_project/src/main/scala.

  3. In my_project create a file called build.sbt. This file will contain build settings for your project.

  4. Edit build.sbt in your preferred text editor.

A build.sbt file is a set of key-value pairs describing various configurations of your project. Values are associated with a given key in the build.sbt file using the following syntax key := value .

Typically three key-value pairs are always defined in build.sbt:

name, the name of you project;
version, the version of your project; and
scalaVersion, the version of Scala to be used with your project.
For example, here is how the contents of a typical build.sbt might appear:
   name := "Hello"
   version := "0.1"
   scalaVersion := "2.11.4"

SBT also allows users to indicate library dependencies for their project. These dependencies can be defined by adding the following in build.sbt:

   libraryDependencies += <groupId> % <artifactID> % <revision>
Note that the operator += appends a library to the previous value of the libraryDependencies attribute (where := would replace the previous value).

SBT Interactive mode

When using SBT in interactive mode users are presented with a command prompt where they can enter a variety commands. The most useful commands for the purposes of this class are:

compile
Compiles the main sources of your project.

run
Runs the main class of the project.

test
Runs any tests defined in the subdirectory src/test/scala/ of your project.

For convenience sbt also allows commands to be automatically rerun whenever a source file of the project is modified. This is done by prefixing a given command with ~. For example,

    ~ compile
will watch for changes in source files and automatically recompile them as needed every time you save your changes.