← Learning

Environment Setup

Scala Environment Setup

We primarily use OSX here at Banno. If you are unfamiliar with the terminal, you should get used to the shell. To get setup, you will need to:

IDE

You are free to use any IDE or text editor you’d like for writing Scala. Several are used by the team, allowing you to ask questions if needed. Be sure to change your formatting so that tabs produce two spaces instead of a tab character, in keeping with Scala formatting practices and so that your work looks normal once you start committing on production code. There are Slack channels for most if not all of the editors listed below, so if you have questions or want to see what tricks others have found you should join!

Formatting

A great way to manage formatting for any IDE is to use EditorConfig, since some of our production code already uses it - Example. All you need to do is download the appropriate plugin after picking one of the editors below. Then, you can specify formatting for .scala files in a project by adding a .editorconfig to the project folder containing:

root = true

[*.scala]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 2

See editorconfig.org for more details.

Atom

Atom is a open source text editor made by github that is easy to use. There is a package you can install to give you scala syntax highlighting. Atom has many community made packages and syntax themes so it may be a bit overwhelming at first, but once you find your preferred settings, Atom will feel natural to you.

https://atom.io/

Scala language syntax highlighting: https://atom.io/packages/language-scala

Sublime

Sublime is a very easy text editor to use, and the install takes about a minute. It’s an easy-to-use editor to use when you’re first starting out. It has the same usual Windows shortcuts and supports Scala out of the box.

http://www.sublimetext.com/

Remember to change the formatting so that tabs produce two spaces instead of a tab character: In Preferences -> Settings - Default make "tab_size": 2, and "translate_tabs_to_spaces": true

Eclipse

Eclipse is a visual IDE that is commonly used in Java development. There is a Scala IDE for Eclipse that, while still not perfect, gives a lot of features that you’d expect in a modern IDE. Using Eclipse for Scala is a memory hog and prone to small issues, but is also the IDE used by most of the Scala language development team and sees regular maintenance.

http://www.eclipse.org/

http://scala-ide.org/

IntelliJ

IntelliJ, like Eclipse, is a visual IDE that boasts good Scala support. While not quite as full featured as Eclipse, it is less of a system hog and is easier to set up.

http://www.jetbrains.com/idea/

Configuring a Minimal UI

The cursive user guide has some great suggestions for decluttering the default Intellij UI. Specifically, disabling editor tabs and navigating via ⌘E (recent files) and ⌘↑ (navigation) can be weirdly liberating.

Configuring Memory

To modify the amount of memory available to Intellij you go to Help > Edit Custom VM Options and set something like this:

-Xms1024m
-Xmx4096m
-XX:ReservedCodeCacheSize=240m
-XX:+UseCompressedOops

Shortcuts

The Intellij scala documentation is definitely worth a read-through, specifically the docs regarding implicits and type annotations.

Emacs

Emacs is a lightweight, speedy editor with quite a few meaningful keyboard shortcuts and niceties that make it the preferred editor by many of our Scala developers. Banno’s Joe Winder has put together an emacs setup with setup instructions in the readme.

If you’d prefer to start fresh: http://www.gnu.org/software/emacs/

Emacs can be a bit overwhelming at first, but there are several guides on how to learn emacs that may be useful. Emacs also has a built in tutorial to teach the basics.

vim

vim can be used by calling: vim ‘‘filename’’

You might have to install vim, if so it can be installed with the command: brew install vim

This tutorial from interlinked and this cheatsheet can help you get started with vim.

If you’d like something specialized, download and use Adam’s vim setup. Feel free to ask him if you have any questions on it.

Set up Github

Your first step will be setting up Git on your machine. Git is how we store all of our source code.

Your next step will be creating your own project to work with over the first month. This will be stored on our local git repo, and tutorials you work through will be added to this project. Add a new project named: “Intern Project [firstname] [lastname]”. Then follow the instructions on that projects page to create the repository

Scala, SBT, And Creating a new Project.

Install Homebrew, SBT, and Scala

Download Homebrew. Brew installs the stuff you need!

If it has not been done for you, you’ll need to set up sbt (The Simple Build Tool). It’s the de-facto build tool for scala. To start:

brew install sbt

Then make sure you have Scala installed.

brew install scala

Artifactory api key

Follow the API Key setup instructions here to sign in to Artifactory with your @jackhenry.com Google account and get your API key.

SBT Information

sbt is the build tool we use for Scala development. For reference, sbt lays out projects in the following way.

<project directory>/
./build.sbt - on this level
    src/
        main/
            resources/ - <files to include in main jar here>
            scala/ - <main Scala sources>
            java/ - <main Java sources>
        test/
            resources - <files to include in test jar here>
            scala/ - <test Scala sources>
            java/ - <test Java sources>

Note: <project directory> is the directory you make to put your sbt project in. Do not put multiple sbt projects in one sbt project directory structure. You will make a mess. It will need to be cleaned up. We do not provide mops.

Starting a new Scala project

New projects are typically materialized with the giter8 templating tool. Banno has several templates.

To create a new service, use Athena. Athena uses one of the aforementioned g8 templates to bootstrap and deploy a service.

To create a new Scala library, try sbt new Banno/template-library.g8. Answer a few prompts to get your project off on the right foot.

Basic commands

Some of the most basic commands you’ll use on a regular basis are:

compile -- Compile the code in src/main/
console -- Pull up an interactive shell
test -- Compile and run the tests for this project
test-only <classname> -- Test a specific test Object
run -- Compile and run from main()

If SBT is still confusing to you, Banno’s Jack Viers does a great job explaining it in more detail.

SBT Compilation problems

You may run into a situation where SBT won’t compile a given project or subproject. This is an issue for bigger or more complex projects that use a lot of resources. You can probably solve this issue by editing the JVM flags being used by SBT. You can either do this for the project you are working on by creating an .sbtopts file in the directory you’re running SBT in, or, you can change it globally for every project by editing /usr/local/etc/sbtopts. You will need to prefix -J- onto any JVM flag you’re wanting SBT to pick up.

Here are some flags you may want set:

-J-Xms4G
-J-Xmx6G
-J-Xss160m
// MaxPermSize ignored from Java 8 onward
-J-XX:MaxPermSize=256m
-J-Djava.awt.headless=true
-J-XX:+CMSClassUnloadingEnabled
-J-Dfile.encoding=utf8

New to Scala?

If you are new to the Scala language, we also have a series of Scala learning modules to get you up to speed.