Scala notes 
top

scala.Option implements Null object pattern.

running scala program

  • Create an object with def main(args: Array[String])
  • pass the class name to scala command
$ scala StringIteratorTest hello

If a method is not returning a value, you don’t need to have a return type. In other words, you don’t need to say void explicitly.

static method doesn’t exist in Scala.

Scala imports java.lang package by default.

Semicolons are not required at the end of statements.

Methods taking one argument can be used with an infix syntax. (Infix syntax? It looks like it does t0 op t1).

  df format now

is same as

  df.format(now)

Everything is an object in Scala. Scala is a pure object-oriented language. Scala doesn’t use primitive types. Functions are objects too.

Type Unit is similar to void in C/C++.

Use override modifier to avoid accidental overriding.

The name Scala stands for “scalable language.”

Scala offers a library that essentially implements Erlang’s actor model.

functional programming

The ideas of functional programming are older than computers. Their foundation was laid in Alonzo Church’s lambda calculus, which he developed in the 1930s.

Functional programming is guided by two main ideas.

  1. functions are first-class values.
  2. no side effects. the operation of a program should map input values to output values rather than change data in place. Immutable data structure are one of the cornerstones of functional programming.

Every useful program has some form of side-effects, as otherwise it wouldn’t be useful influence the outside world. The key is to minimize the code has side-effects.

Scala is a hybrid imperative/functional language.

list

  • Lists are immutable.
  • Lists have a recursive structure, whereas arrays are flat.
  • Lists are homogeneous and the elements of a list all have the same type.
  • Lists are the immutable linked-list structure.
  • It is fast addtion and removal of initial elements.

flatMap operator takes a function returning a list of elements as its right operand. It combines all the results into a list.

Concrete method is a method with concrete implementation. It is opposite of abstract method.

Unline Java, there is no virtual keyword in Scala.