ScalaSchool

What is Scala?

Scala combines object-oriented and functional programming in one concise, high-level language. Scala’s static types help avoid bugs in complex applications, and its JVM and JavaScript runtimes let you build high-performance systems with easy access to huge ecosystems of libraries.

What is functional programming?

In functional programming, functions are what we call first-class citizens. This means that functions are passed as objects just like integers and arrays. Functions may have functions as parameters and return values, like an other data type. We generally contrast functional programming with object oriented programming or imperative programming. In imperative programming, we use for loops to access all the elements of an array. It’s typical in imperative programming to modify the elements of an array. In functional programming, we will use functions like map to access every element of a collection, and rather than modifying the collection, we create a new one. The functional style, while it can take a little to get used to, can lead to cleaner more concise code.

Compare the two styles to declar an array and double each element of the array

// Imperative Style
val arr = new Array[Int](100)

{
  var i = 0
  while (i < 100) {
    arr(i) = i
    i = i + 1
  }
}

// mutate the original array

{
  var i = 0
  while (i < 100) {
    arr(i) = arr(i) * 2
    i = i + 1
  }
}
// Functional style
val arr = (0 until 100)

// Use map and make a new Array
val newArr = arr.map(_ * 2)

Pros and Cons of Functional Programming

Functional Programming Benefits:

Functional Programming Downsides:

Still not convinced? Read the Benefits of Functional Programming.

Scala

While Scala is a functional programming language, it supports imperative programming as well. While a pure functional language does not have loops, loops are part of the Scala language, though are generally used infrequently.

Scala is a strongly-typed, object-oriented, functional programming language.

Scala Features:

Scala Benefits:

Scala Downsides:

What most people use Scala For

Popular enterprise frameworks like Spark, Akka and Kafka were written in Scala. Many scala developers work on building apps on top of these frameworks.

Scala is used heavily at Twitter, Netflix, and many others