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,

Saturday, May 21, 2016

Getting Started with Scala

So you want to learn Scala. I will teach Scala to you from start to finish, but I do assume you at least understand some basics, like what is a variable; what is a function; and what does compile mean.

You don't need to already know any syntax or even definitions of terms like higher-order functions. I don't teach everything about programming, but if you feel comfortable with some very basic programming concepts, I'll take it from there.

What is Scala?


You can write any type of application with Scala. If you want to write a traditional desktop app, you can write it in Scala. If you want to write scripts and command line tools, you can do it in Scala. If you want to write web services, you can do it in Scala. If you want to write JavaScript code for your website, you can do it in Scala. Scala is highly versatile and works for nearly any solution you need an application written for.

Scala is a programming language that runs on the Java Virtual Machine (JVM). Scala has been around for almost as long at Java. Scala was originally written as an better alternative to Java. Scala can also run on other VM's, but the JVM seems to be the most common platform for Scala. Because Scala runs on the JVM, it was designed to interact with Java and existing Java projects with minimal fuss. Scala's Java interop is excellent and easy.

Scala itself is a hybrid between Object-Oriented Programming (OOP) and Functional Programming (FP). Don't worry if you don't fully understand what Object-Oriented Programming and Functional Programming are. I will delve more into them in future tutorials. It's very common for experienced programmers to not fully understand Functional Programming, so I expect to produce a lot of tutorials on that end of things.