Scala Overview

Overview

Scala is a programming language that fuses functional programming with object-oriented programming and adds static typing.
It is a language that runs on the JVM and integrates seamlessly with Java.

Functional Programming

  • Functions are objects; functions are first-class values. A function has the same status as a string or an integer: it can be passed as a function argument, returned as a function’s return value, and stored in a variable. You can also define functions inside functions, just as you define integers, and define anonymous functions, inserting a function anywhere in the code.
  • Immutable data structures are the cornerstone of functional programming.
  • Methods should have no side effects, i.e., they are reentrant.

Static Typing

  • It determines the types of variables and expressions. All types are explicitly specified rather than changing dynamically, yet it nicely solves the problem of excessive verbosity in programs.

  • It avoids redundancy through type inference.

  • It gains flexibility through pattern matching.

  • Benefits:

    • Type checking
    • Safe refactoring
  • Users can define their own classes or libraries.

    • Comment: can’t any language do this? There’s nothing special about it.
  • The Actor concurrency programming model

    • Comment: it’s really just message-based asynchronous programming — new wine in old bottles. Asynchronous programming frameworks are all based on the message-driven Actor model. The one difference is that Scala’s Actor programming framework is simpler to use and better encapsulated.

enter image description here

Intellectual Origins of Scala

  • It adopts most of Java & C#: expressions, statements, and code blocks are mostly the same as in Java. It also borrows many Java elements, including primitive types, class libraries, and execution models.
  • The uniform object model comes from Smalltalk.
  • The Actor library comes from Erlang.
  • The functional programming style comes from the ML family of languages, represented by SML/OCaml/F#.
  • The uniform access principle for method calls and field selection comes from Eiffel.