Programmer's Wiki
Advertisement

Scala is a multi-paradigm programming language designed to express common programming patterns in a concise, elegant, and type-safe way. It smoothly integrates features of object-oriented and functional languages.

Object-oriented features[]

Scala is a pure object-oriented language in the sense that every value is an object. Types and behavior of objects are described by classes and traits. Class abstractions are extended by subclassing and a flexible mixin-based composition mechanism as a clean replacement for multiple inheritance.

Functional programming[]

Scala is also a functional language in the sense that every function is a value. Scala provides a lightweight syntax for defining anonymous functions, it supports higher-order functions, it allows functions to be nested, and supports currying. Scala's case classes and its built-in support for pattern matching model algebraic types used in many functional programming languages.

Furthermore, Scala's notion of pattern matching naturally extends to the processing of XML data with the help of regular expression patterns. In this context, sequence comprehensions are useful for formulating queries. These features make Scala ideal for developing applications like web services.

Static typing[]

Scala is equipped with an expressive type system that enforces statically that abstractions are used in a safe and coherent manner. In particular, the type system supports:

  • generic classes,
  • variance annotations,
  • upper and lower type bounds,
  • classes and abstract types as object members,
  • compound types,
  • explicitly typed self references,
  • views, and
  • polymorphic methods.

Extensibility[]

The design of Scala acknowledges the fact that in practice, the development of domain-specific applications often requires domain-specific language extensions. Scala provides a unique combination of language mechanisms that make it easy to smoothly add new language constructs in form of libraries:

  • any method may be used as an infix or postfix operator, and
  • closures are constructed automatically depending on the expected type (target typing).

A joint use of both features facilitates the definition of new statements without extending the syntax and without using macro-like meta-programming facilities.

Platform independence[]

Scala is primarily built to leverage the JVM and have interoperability with Java, but Scala also has other official compilers, such as Scala.js and Scala Native. A deprecated and unmaintained compiler also exists for .NET CLR.

Hello World example[]

The "Hello, World!" program written in Scala:

object HelloWorld {
  def main(args: Array[String]): Unit = 
    println("Hello, World!")
}


An alternative to the main entry-point function is to extend the App trait. This allows the whole object to become the main method:

object HelloWorld extends App {
  println("Hello, World!")
}

External links[]

Advertisement