Scala (programming language)

Scala (programming language)

Infobox programming language
name = Scala

paradigm = Multi-paradigm: functional, object-oriented
year = 2003
designer = Martin Odersky
developer = Programming Methods Laboratory of EPFL
latest_release_version = 2.7.1
latest_release_date = May 5, 2008
typing = static, strong, inferred
implementations = Scala
dialects =
influenced_by = Java, Haskell, Standard ML, Objective Caml, Smalltalk
influenced =
website = [http://www.scala-lang.org www.scala-lang.org]

Scala (Scalable Language) is a multi-paradigm programming language designed to integrate features of object-oriented programming and functional programming.Martin Odersky et al, An Overview of the Scala Programming Language, 2nd Edition]

Platform

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.cite web
url=http://www.scala-lang.org/docu/clr/
title=Scala on .NET
publisher=Programming Methods Laboratory of EPFL
quote="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."
date=2008-01-07
accessdate=2008-01-15
] An alternative implementation exists for the .NET platform, but it has not been kept up to date.

History

Scala was created at the École Polytechnique Fédérale de Lausanne (EPFL) in 2001 by Martin Odersky. It was released publicly on the Java platform in January 2004, and on the .NET platform in June the same year. A second version of the language was released in March 2006.

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.

Implementing some of the most advanced functional programming constructs in Scala may occasionally be limited by the fact that tail call optimizations are not supported completely, because the JVM lacks the byte codes for implementing them efficiently. In these situations one simply has to go back to traditional procedural programming.

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

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

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

Platform independence

Scala is designed to interoperate well with popular programming environments like the Java 2 Runtime Environment (JRE) and the .NET CLR. In particular, the interaction with mainstream object-oriented languages like Java and C# is as smooth as possible.

In other words, Scala can make use of all libraries available for Java/C#, addressing the common drawback of using advanced functional languages which is that the small community, much of it centered around academia, often does not get to implementing quality libraries for common real-world tasks such as relational database access, XML processing, regular expressions, and so on. Scala can accomplish those tasks in a manner very similarly to how one would in Java or C#.

Scala has the same compilation model (separate compilation, dynamic class loading) as Java and C#, and allows thousands of high-quality libraries to be accessed.

Hello World example

Here is the canonical Hello world program written in Scala:

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

or

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

Notice how similar it is to the stand-alone Hello World application for Java. The notable difference is that we do not declare anything to be static or void; the object keyword gives us a singleton object, freeing us from having to invoke any such constructs.

One would then compile this from the command line roughly as follows, assuming it was saved in a filename called HelloWorld.scala:

> scalac HelloWorld.scala

One would then run it like so:

> scala -classpath . HelloWorld

This is analogous to how one compiles and runs a Java "hello world" program. 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)'

Testing

There are some ways to test code in Scala:
* The scala-library itself provides SUnit, an xUnit like framework using Assertions.
* The [http://rehersal.sourceforge.net/ Rehersal] project provides a more extensive framework using Expectations and natural language for test names. It also has integration with Apache Ant.
* [http://code.google.com/p/scalacheck/ ScalaCheck]
* [http://code.google.com/p/specs/ specs] , a Behavior driven development library for Scala
* JUnit

References

Books

* [http://www.artima.com/shop/forsale Programming in Scala] - A comprehensive step-by-step guide by Martin Odersky, Lex Spoon, and Bill Venners.

External links

* [http://www.scala-lang.org/ Scala website]
* [http://scala.sygneca.com/ Scala Wiki]
* [http://www.codenotifier.com/projects/90 Scala source repository commits tracker]
* [http://en.literateprograms.org/Category:Programming_language:Scala Literate Programs - Scala]
* [http://www.scala-lang.org/community/ The Scala Community]
*Scala Presentation From The Googleplex [http://video.google.com/videoplay?docid=553859542692229789] (video) - given by Martin Odersky, creator of the language; [http://lampwww.epfl.ch/~odersky/talks/google06.pdf accompanying slides from the talk]
* [http://rehersal.sourceforge.net/ Rehersal (A testing framework for Scala)]
* [http://www.carlobonamico.com/scala.php The Scala Search Engine]
* [http://liftweb.net/ Lift Web Framework]
* [http://www.se-radio.net/index.php?post_id=226313 Podcast Interview with Martin Odersky on Scala]
* [http://code.google.com/p/specs/ specs (BDD framework for Scala)]
* [http://www.artima.com/scalatest/ ScalaTest (test framework)]
* [http://code.google.com/p/scalacheck/ ScalaCheck (scala implementation of QuickCheck]
* [http://wiki.workingmouse.com/index.php/Scalaz Scalaz]


Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать курсовую

Look at other dictionaries:

  • Multi-paradigm programming language — A multi paradigm programming language is a programming language that supports more than one programming paradigm. As Leda designer Tim Budd holds it: The idea of a multiparadigm language is to provide a framework in which programmers can work in… …   Wikipedia

  • Fan (programming language) — Infobox programming language name = Fan logo = paradigm = multi paradigm year = 2007 designer = developer = Brian Frank, Andy Frank latest release version = 1.0.30 latest release date = release date|2008|07|30 typing = static, dynamic… …   Wikipedia

  • Erlang (programming language) — Erlang Paradigm(s) multi paradigm: concurrent, functional Appeared in 1986 Designed by Ericsson …   Wikipedia

  • Processing (programming language) — Processing Paradigm(s) object oriented Appeared in 2001; 9 years ago (2001) …   Wikipedia

  • Nu (programming language) — Nu Paradigm(s) structured, imperative, object oriented Appeared in 2007 Designed by Tim Burks Developer Tim Burks Stable release 2.0 …   Wikipedia

  • Fortress (programming language) — infobox programming language name = Fortress paradigm = year = designer = developer = Sun Microsystems latest release version = 1.0 latest release date = April 2008 latest test version = latest test date = typing = implementations = dialects =… …   Wikipedia

  • Haskell (programming language) — Haskell Paradigm(s) functional, lazy/non strict, modular Appeared in 1990 Designed by Simon Peyton Jones, Lennart Aug …   Wikipedia

  • Visual programming language — A Visual programming language (VPL) is any programming language that lets users specify programs by manipulating program elements graphically rather than by specifying them textually. A VPL allows programming with visual expressions, spatial… …   Wikipedia

  • Java (programming language) — infobox programming language name = Java paradigm = Object oriented, structured, imperative year = 1995 designer = Sun Microsystems latest release version = Java Standard Edition 6 (1.6.0) latest release date = latest test version = latest test… …   Wikipedia

  • ML (programming language) — ML Paradigm(s) multi paradigm: imperative, functional Appeared in 1973 Designed by Robin Milner others at the University of Edinburgh Typing discipline static, strong, inferred …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”