Scala (programming language)

From Seo Wiki - Search Engine Optimization and Programming Languages

Jump to: navigation, search
File:Scala logo.png
Paradigm Multi-paradigm: functional, object-oriented, imperative
Appeared in 2003
Designed by Martin Odersky
Developer Programming Methods Laboratory of EPFL
Stable release 2.7.7 (October 28, 2009; 367009291 ago)
Typing discipline static, strong, inferred, structural
Influenced by Java, Pizza,[1] Haskell, Erlang, Standard ML, Objective Caml, Smalltalk, Scheme

Scala (pronounced /ˈskɑːlə, ˈskeɪlə/) is a multi-paradigm programming language designed to integrate features of object-oriented programming and functional programming.[1] The name Scala stands for "scalable language", signifying that it is designed to grow with the demands of its users.


Platforms and license

Scala runs on the Java platform (Java Virtual Machine) and is compatible with existing Java programs. It also runs on Java Platform, Micro Edition Connected Limited Device Configuration.[2] An alternative implementation exists for the .NET platform, but it has not been kept up to date.[3]

Scala has the same compilation model as Java and C# (separate compilation, dynamic class loading), so Scala code can call Java libraries (or .NET libraries in the .NET implementation).

Scala's operational characteristics are the same as Java's. The Scala compiler generates byte code that is nearly identical to the Java compiler. In fact, you can decompile Scala code to readable Java code, with the exception of certain constructor operations. To the JVM, Scala code and Java code are indistinguishable. The only difference is a single extra runtime library, scala-library.jar.[4]

The Scala software distribution, including compiler and libraries, is released under a BSD license.[5]


The design of Scala started in 2001 at the École Polytechnique Fédérale de Lausanne (EPFL) by Martin Odersky, following on from work on Funnel, a programming language combining ideas from functional programming and Petri nets.[6] Odersky had previously worked on Generic Java and javac, Sun's Java compiler.[6] Scala was released late 2003 / early 2004 on the Java platform, and on the .NET platform in June 2004.[1][6][7] A second version of the language, v2.0, was released in March 2006.[1]

As of Oct 2009, the latest release is version 2.7.7. Features planned for Scala 2.8 include an overhaul of the Scala collections library, named and default parameters for methods, package objects, and continuations.[8]

Object-oriented features

Scala is a pure object-oriented language in the sense that every value is an object. Data types and behaviors of objects are described by classes and traits. Class abstractions are extended by subclassing and by a flexible mixin-based composition mechanism to avoid the problems of multiple inheritance.

Functional programming

Scala also supports functional programming. The language provides a lightweight syntax for defining anonymous functions, supports higher-order functions, allows functions to be nested, and supports currying. Using the keyword "lazy" defers the initialization of a variable until this variable is used. Evaluation of delimited continuations will be supported in version 2.8.

Scala's case classes and its built-in support for pattern matching model Algebraic data types used in many functional programming languages.

Tail call optimization is not supported completely, because the JVM lacks tail call support. In simple cases, the Scala compiler can optimize tail calls into loops.[9]

An implementation of a Quicksort algorithm in functional style, for comparison with the Erlang Quicksort example:

 def qsort(list: List[Int]): List[Int] = 
   list match {
     case Nil => Nil
     case pivot::tail => qsort(tail.filter(_ < pivot)) ::: pivot :: qsort(tail.filter(_ >= pivot))

Static typing

Scala is equipped with an expressive static type system that enforces the safe and coherent use of abstractions. In particular, the type system supports:


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 the 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.

Software using Scala

Lift is a free web application framework that aims to deliver benefits similar to Ruby on Rails. The use of Scala means that any existing Java library and Web container can be used in running Lift applications.

In April 2009 Twitter announced they had switched large portions of their backend from Ruby to Scala and intended to convert the rest.[10] In addition, Wattzon has publicly been noting that its entire platform has been written from the ground up in Scala.[11]

Foursquare (service) uses Scala and Lift.

"Hello world" example

Here is the classic Hello world program written in Scala:

 object HelloWorld extends Application {
   println("Hello, world!")


 object HelloWorld {
   def main(args: Array[String]) {
     println("Hello, world!")

Notice how similar it is to the stand-alone Hello World application for Java. A notable difference is that nothing is declared to be static; the singleton created by the object keyword is used instead.

Assuming the program is saved in a file named HelloWorld.scala, it can then be compiled from the command line:

> scalac HelloWorld.scala

To run it:

> scala -classpath . HelloWorld

This is analogous to how a Java "hello world" program is compiled and run. Indeed, Scala's compilation and execution model is identical to that of Java, making it compatible with Java build tools such as Ant.

It is also possible to feed this program directly into the Scala interpreter, using the option -i (to load code from the file) and the option -e (to execute additional code needed to actually invoke the HelloWorld object's method):

> scala -i HelloWorld.scala -e 'HelloWorld.main(null)'


There are some ways to test code in Scala:

The built-in Scala library SUnit is deprecated and will be removed in version 2.8.0, see SUnit documentation.

See also


  1. 1.0 1.1 1.2 1.3 Martin Odersky et al., An Overview of the Scala Programming Language, 2nd Edition
  2. "Scala on .NET". Programming Methods Laboratory of EPFL. 2008-01-07. Retrieved 2008-01-15. "Scala is primarily developed for the JVM and embodies some of its features. Nevertheless, its .NET support is designed to make it as portable across the two platforms as possible." 
  6. 6.0 6.1 6.2 Martin Odersky, "A Brief History of Scala", weblogs, June 9, 2006
  7. Martin Odersky, "The Scala Language Specification Version 2.7"
  8. Scala 2.8 Preview
  9. Tail calls, @tailrec and trampolines
  10. Greene, Kate (April 1, 2009). "The Secret Behind Twitter's Growth, How a new Web programming language is helping the company handle its increasing popularity.". Technology Review. MIT. Retrieved April 6, 2009. 
  11. Cloud, Jeremy (March 10, 2009). "Scala + WattzOn, sitting in a tree...". 


External links

cs:Scala (programovací jazyk) da:Scala (programmeringssprog) de:Scala (Programmiersprache) es:Lenguaje de programación Scala fr:Scala (langage) it:Scala (linguaggio di programmazione) lt:Scala nl:Scala (programmeertaal) ja:Scala pl:Scala (język programowania) pt:Scala (linguagem de programação) ru:Scala (язык программирования) fi:Scala sv:Scala (programmeringsspråk) uk:Scala (мова програмування) zh:Scala

Personal tools

Served in 1.012 secs.