English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Introduction to Scala

Scala is an abbreviation for Scalable Language, and it is a multi-paradigm programming language

Martin Odersky of the Swiss Federal Institute of Technology in Lausanne (EPFL) in2001year, based on the work of Funnel, Scala was started to be designed.

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 Scala for the Java platform was released at2003year-end/2004was released at the beginning of the year. The Scala release for the .NET platform was released at2004Year6month. The second version of the language, v2.0, released in2006Year3month.

As of2009Year9In a month, the latest version is version2.7.6 .Scala 2.8Expected features include the rewritten Scala class library (Scala collections library), named parameters and default parameters for methods, package objects (package object), and Continuation.

2009Year4In a month, Twitter announced that they have migrated most of their backend programs from Ruby to Scala, and the rest are also planned to be migrated. In addition, Wattzon has publicly declared that its entire platform is based on Scala infrastructure.

Scala Features

Object-Oriented Features

Scala is a pure object-oriented language where every value is an object. The data type and behavior of objects are described by classes and traits.

There are two ways to extend the class abstraction mechanism: one way is subclass inheritance, and the other way is a flexible mixin mechanism. Both approaches can avoid the various problems associated with multiple inheritance.

Functional Programming

Scala is also a functional language, where functions can be used as values. Scala provides lightweight syntax for defining anonymous functions, supports higher-order functions, allows nested functions to be layered, and supports currying. Scala's case class and its built-in pattern matching are analogous to algebraic types commonly used in functional programming languages.

Further, programmers can use Scala's pattern matching to write code similar to regular expressions to process XML data.

Static Typing

Scala has a type system that ensures code safety and consistency through compile-time checks. The type system specifically supports the following features:

  • Generic Classes

  • Covariance and Contravariance

  • Annotations

  • Upper and lower bounds constraints on type parameters

  • Classify and abstract types as object members

  • Composite Types

  • Explicitly specify the type when referring to itself

  • Views

  • Polymorphic Methods

Extensibility

The design of Scala adheres to the fact that in practice, the development of application-specific applications often requires language extensions specific to the field. Scala provides many unique language mechanisms that can be easily and seamlessly added as 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, where Actors are entities similar to threads that send and receive messages through email. Actors can reuse threads, so millions of Actors can be used in a program, whereas threads can only create thousands. In2.10In later versions, Akka is used as the default Actor implementation.

Who Uses Scala

  • 2009Year4Twitter announced that they have migrated most of their backend programs from Ruby to Scala, and the rest are also planned to be migrated.

  • Additionally, Wattzon has publicly declared that its entire platform is already written based on Scala infrastructure.

  • UBS Group uses Scala in general products.

  • Coursera uses Scala as a server-side language.

Scala Web Frameworks

The following lists3The following are some of the currently popular Scala Web application frameworks: