Scala Introduction
Scala is an acronym for Scalable Language, a multi-paradigm programming language.
Martin Odersky of the Swiss Federal Institute of Technology in Lausanne (EPFL) began designing Scala in 2001 based on his work with Funnel.
Funnel is a programming language that combines functional programming concepts with Petri nets.
Odersky's previous work included Generic Java and javac (Sun Java compiler). Scala for the Java platform was released at the end of 2003/early 2004. Scala for 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 was 2.7.6. Features expected in Scala 2.8 included a rewritten Scala collections library, named and default parameters for methods, package objects, and Continuation.
In April 2009, Twitter announced that they had migrated most of their backend code from Ruby to Scala, with plans to migrate the rest. Additionally, Wattzon has publicly stated that its entire platform is written on Scala infrastructure.
Scala Features
Object-Oriented Features
Scala is a purely object-oriented language, where every value is an object. The data types and behaviors of objects are described by classes and traits.
There are two ways to extend class abstraction mechanisms: one is through subclass inheritance, and the other is a flexible mixin mechanism. These two approaches can avoid the various issues associated with multiple inheritance.
Functional Programming
Scala is also a functional language, where functions can also be used as values. Scala provides lightweight syntax for defining anonymous functions, supports higher-order functions, allows nesting of multiple levels of functions, and supports currying. Scala's case classes and built-in pattern matching are equivalent to algebraic types commonly used in functional programming languages.
Furthermore, programmers can use Scala's pattern matching to write code similar to regular expressions for processing XML data.
Static Typing
Scala has a type system that ensures the safety and consistency of the code through compile-time checks. The type system specifically supports the following features:
Generic classes
Covariance and contravariance
Annotations
Upper and lower bounds of type parameters
Treating traits and abstract types as object members
Compound types
Explicitly specifying types when referring to oneself
Views
Polymorphic methods
Extensibility
Scala's design is based on the fact that in practice, the development of domain-specific applications often requires domain-specific language extensions. Scala provides many unique language mechanisms that can easily and seamlessly add new language structures in the form of libraries:
Any method can be used as a prefix or suffix operator
Closures can be automatically constructed based on the expected type.
Concurrency
Scala uses Actors as its concurrency model, which are thread-like entities that send and receive messages through mailboxes. Actors can reuse threads, so millions of Actors can be used in a program, while only thousands of threads can be created. In versions after 2.10, Akka is used as its default Actor implementation.
Who Uses Scala
In April 2009, Twitter announced that they had migrated most of their backend code from Ruby to Scala, with plans to migrate the rest.
Additionally, Wattzon has publicly stated that its entire platform is written on Scala infrastructure.
UBS uses Scala in general products.
Coursera uses Scala as a server language.
Scala Web Frameworks
The following are two of the currently popular Scala web application frameworks:
-
-