Skip to content

Instantly share code, notes, and snippets.

@metasim
Last active December 22, 2015 07:29
Show Gist options
  • Select an option

  • Save metasim/6438485 to your computer and use it in GitHub Desktop.

Select an option

Save metasim/6438485 to your computer and use it in GitHub Desktop.
Example reveal.js markdown input, content from in-progress presentation on Scala

What is Scala?

  • A modern, statically typed programming language built upon the Java ecosystem
  • Elegant mix of object orientation and functional programming paradigms
  • Designed to be used by real developers, solving real-world problems
  • Runs on the JVM, providing full interoperability with Java APIs
  • By Martin Odersky, author of the modern `javac` compiler

Why Scala?

  • Understanding Scala requires understanding this mixture of concepts
  • Scala attempts to blend three seemingly orthogonal paradigms of thought into one language. These are:
    • Expressive syntax with static typing
    • Functional programming and object-oriented programming
    • Advanced language features and rich Java integration
  • These traits pointedly address the modern demands of data science deployment.

Why Now?

  • Responsiveness to data processing demands are at the core of ERI's business
  • Maintaining our competative advantage necessitates evaluating and refining our practices
  • Scala maturity and acceptence has passed an inflection point making it ready for adoption

RedMonk Programming Language Rankings


Who's Using Scala

Scala in the Enterprise

  • eBay
  • Twitter
  • LinkedIn
  • ...

Approaches to Adoption

Scala as a Better Java

  • Type inference
  • Case classes
  • Named and default arguments
  • Tuples
  • Lazy values

Functional Programming in Scala

  • In Scala, functions are objects, allowing program construction through the definition and composition of objects and functions.
  • Therefore Scala enables the developer to focus on “nouns” or “verbs” in a program, depending on the modality that best expresses the problem at hand.

Distinguishing Language Features

Object-oriented programmingFunctional programming
Composition of objects (nouns)Composition of functions (verbs)
Encapsulated stateful interactionDeferred side effects
Iterative algorithmsRecursive algorithms and continuations
Imperative flowLazy evaluation
Pattern matching

[Scala in Depth][1]


Expressive Syntax

  • Scala also blends expressive syntax with static typing.
  • Mainstream statically typed languages tend to suffer from verbose type annotations and boilerplate syntax.
  • Scala takes a few lessons from the ML programming language and offers static typing with a nice expressive syntax.
  • Code written in Scala can look as expressive as dynamically typed languages, like Ruby, while retaining type safety.

Sum of Squares: Java

Procedural Approach

    public int sumSquare(int[] list) {
        int s = 0;
        for(int i = 0; i < list.length; i++) {
            s += list[i] * list[i]; 
        }
        return s;
    }
    int result = sumSquare(new int[] { 1, 2, 3}));
    System.out.println(result);

Sum of Squares: Scala

Functional Approach

val ar = Array(1,2,3)
def square(x:Int) = x * x
def add(s:Int,i:Int) = s+i

val result = ar.map(square).foldLeft(0)(add)
println(result)

Fibonacci: Java

Recursive Approach

public class Fibonacci {
    public static long fib(final int n) {
        if (n < 2) {
            return n
        }
        else {
            fib(n - 1) + fib(n - 2)
        }
    }
}

Fibonacci: Scala

Recursive with Pattern Matching

def fib(i:Int):Int = i match {
    case 0 => 0
    case 1 => 1
    case _ => fib(i-1) + fib(i-2)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment