Scala

An Introduction

 

Summary

  • What is Scala?
  • Why Scala?
  • Installation and Setup
  • Basics

What is Scala?

Scala is a typesafe programming language that compiles to bytecode on the JVM

  • First developed by Prof. Martin Odersky at École Polytechnique Fédérale de Lausanne (EPFL) in 2004
  • Today adopted by many noteworthy enterprises:
    • Twitter, Netflix, Bloomberg, CreditSuisse, ING Bank, Databricks, Confluent, Mesosphere, LinkedIn, FourSquare, Lightbend, SoundCloud, Spotify, Nest, Sungevity, Workday, Pinterest, Tumblr, Airbnb, Apple, Sony, Cisco, eBay, The New York Times, The Guardian, BBC, Huffington Post, etc.
  • Most of the Scala library is maintained by Lightbend (formerly Typesafe) based in SF
  • Popularized by Twitter's switch from Ruby to Scala for many of its distributed services

At a Glance

Why Scala?

  • Systems language
  • Strongly-typed
  • Very expressive
    • first-class functions
    • combinators
    • closures
    • case classes
  • Concise and literal syntax
  • Open source 
  • Java interoperability
  • Platform agnostic
  • Rich collections library
  • Blazing fast concurrency
  • Emphasis on immutability
class Point(object):
    
    def __init__(self, _x, _y):
        self._x = _x; self._y = _y
        
    @property
    def x(self):
        return self._x

    @x.setter
    def x(self, value):
        self._x = value
        
    @property
    def y(self):
        return self._y
        
    @y.setter
    def y(self, value):
        self._y = value
point.py
public class Point {

    private int x;
    private int y;

    public Point(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public int getX() { return x; }

    public int getY() { return y; }

    public void setX(int x) { this.x = x; }

    public void setY(int y) { this.y = y; }

}
Point.java
case class Point(var x: Int, var y: Int)
Point.scala

That's it! You're done.

No boilerplate!

Concurrency

 

  • Scala adds some neat abstractions
    around Java's concurrency primitives
    • Futures & Promises
    • Actors

 

  • Some cool open source projects with signficant portions written in Scala
    • Play! Web Framework
    • Scalatra
    • Finagle, Finatra, Scalding (Twitter)
    • Akka / Spray
    • Breeze
    • Apache Spark
    • Apache Kafka
    • Apache Flink
    • Marathon

 

  • A few apps Grid Systems has written in Scala
    • dgms-platform
    • realtime-aggregator
    • spark-ingestion-application
    • websocket-rabbitmq-bridge
    • rabbitmq-cassandra-bridge
    • nest-bridge
    • steffes-bridge
    • sep2-bridge

Installation and Setup

Basics

ScalaProgrammingLanguage

By Nathan Murthy

ScalaProgrammingLanguage

  • 244