Saturday, June 4, 2016

Scala for OSX

Just a quick note on setting up Scala on OS X. There are several ways to go about getting Scala to work in the Terminal on OS X, but the quickest way I've found is putting Scala on the $PATH and then opening up a new Terminal window.

Once Scala is on the $PATH, it is easy to start Scala's REPL from any Terminal window and just start using Scala for quick tasks directly from the REPL in the Terminal. OS X is a great platform to program Scala from.

Friday, June 3, 2016

Scala Numeric Value Types and Math

Now that we've done an overview of Scala, let's get into what computers do best—math.

In languages such as Java, numeric types are generally primitives of some sort. Scala is purely Object Oriented, so numeric types are always objects. Having numeric types as objects means that methods affecting numbers are called on the numeric types directly. All numeric types in Scala are AnyVal objects.

What that means is that 1+1 and 1.+(1) are the same thing in Scala. The first example does not have the dot or the parenthesis, but both the dot and parenthesis are optional in Scala. For anyone familiar with Java-like languages, the second example looks a lot like a function or method, because it is. They both are. The mathematical operators in Scala are just method calls on AnyVal objects.
In an app, the previous examples would look like this,