Appendix A. Introduction to Scala

 

Scala is a powerful combination of both object oriented and functional programming approaches, and its language constructs can often seem somewhat terse to newcomers. This appendix aims to give you a rough guide to Scala and serve as enough background for you to make full use of this book. Understand that this is only a top-level view of Scala features and it can’t cover anywhere near all of Scala’s capabilities. For a more detailed introduction to the broader language, I suggest picking up a copy of Nilanjan Raychaudhuri’s Scala in Action, also from Manning.

As a language, Scala only has a few core features. The vast majority of features are implemented as libraries, which results in a language that has a very tight core. The following sections cover this core of features that are then used to build the rest of the standard library.

A.1. Variables, values, and immutability

Scala uses a range of mechanisms to allocate objects in memory, and if you’ve programmed in nearly any other language, you’ll be familiar with the concept of a variable. It’s an item that you typically assign something (like a string) to, and then reference (and possibly mutate) at a later stage in your program.

To create variables in Scala you can do the following:

var thing = "sdfdsf"
var another: Int = 1234

This provides a means to create a variable, which can be mutated later in your application code.

A.2. Classes, methods, traits, and functions

A.3. Collections

A.4. Pattern matching

A.5. Implicits