Scala - Introduction
Scala is short for Scalable Language and is a multi-paradigm programming language.
Martin Odersky of the Federal Institute of Technology in Lausanne (EPFL) began designing Scala in 2001 based on the work of Funnel.
Funnel is a programming language that combines functional programming ideas with Petri nets.
Odersky's previous work was Generic Java and javac (Sun Java Compiler). The Java platform Scala was released in late 2003/early 2004. Scala on the .NET platform was released in June 2004. The second version of the language, v2.0, was released in March 2006.
As of September 2009, the latest version is version 2.7.6. The expected features of Scala 2.8 include the rewritten Scala collections library, method naming parameters and default parameters, package objects, and Continuation.
In April 2009, Twitter announced that they had migrated most of their backend applications from Ruby to Scala, and the rest were also going to be migrated. In addition, Wattzon has publicly stated that its entire platform has been written based on the Scala infrastructure.
Scala is a pure object-oriented language, and each value is an object. The data type and behavior of an object are described by classes and traits.
The class abstraction mechanism can be extended in two ways: one is subclass inheritance and the other is flexible blending mechanism. These two approaches can avoid the problems of multiple inheritance.
Scala is also a functional language whose functions can also be used as values. Scala provides a lightweight syntax for defining anonymous functions, supporting higher-order functions, allowing nested multi-layer functions, and supporting currying. Scala's case class and its built-in pattern matching are equivalent to the algebraic types commonly used in functional programming languages.
Further, programmers can use Scala's pattern matching to write code like regular expressions to process XML data.
Scala has a type system that ensures code security and consistency through compile-time checks. The type system specifically supports the following features:
- Generic class
- Covariation and Inversion
- Upper and lower bounds of type parameters
- Class and abstract types as object members
- Composite type
- Explicitly specify the type when referring to yourself
- Polymorphic method
Scala's design is based on the fact that in practice, a domain-specific application development often requires language extensions specific to that domain. Scala provides a number of unique language mechanisms that make it easy to seamlessly add new language constructs in the form of libraries:
- Any method can be used as a prefix or suffix operator
- Closures can be constructed automatically based on the expected type.
Scala uses Actors as its concurrency model. Actors are thread-like entities that send messages through the mailbox. Actors can reuse threads, so millions of Actors can be used in a program, and threads can only create thousands. In versions later than 2.10, Akka was used as its default Actor implementation.
Who used Scala
- In April 2009, Twitter announced that they had migrated most of their backend applications from Ruby to Scala, and the rest were also going to be migrated.
- In addition, Wattzon has publicly stated that its entire platform has been written based on the Scala infrastructure.
- UBS uses Scala for general products.
- Coursera uses Scala as a server language.
Scala Web Framework
The following are two of the more popular Scala web application frameworks: