Declarative programming

From Wikipedia, the free encyclopedia

  (Redirected from Declarative language)
Jump to: navigation, search

In computer science, declarative programming is a programming paradigm that expresses the logic of a computation without describing its control flow.[1] Many languages applying this style attempt to minimize or eliminate side effects by describing what the program should accomplish, rather than describing how to go about accomplishing it.[2] This is in contrast with imperative programming, which requires an explicitly provided algorithm.

Declarative programming often considers programs as theories of a formal logic, and computations as deductions in that logic space. Declarative programming has become of particular interest recently, as it may greatly simplify writing parallel programs [1].

Common declarative languages include those of regular expressions, logic programming and functional programming.

Contents

[edit] Definition

Declarative programming is often defined as any style of programming that is not imperative. A number of other common definitions exist that attempt to give the term a definition other than simply contrasting it with imperative programming. For example:

These definitions overlap substantially.

[edit] Subparadigms

Declarative programming is an umbrella term that includes a number of more well-known programming paradigms.

[edit] Functional programming

Functional programming, and in particular purely functional programming, attempts to minimize or eliminate side effects, and is therefore considered declarative. Most functional languages, however, do permit side effects in practice.

While functional languages typically do appear to specify "how," a compiler for a purely functional programming language is free to extensively rewrite the operational behavior of a function, so long as the same result is returned for the same inputs. This can be used to, for example, make a function compute its result in parallel, or to perform substantial optimizations (such as deforestation) that a compiler may not be able to safely apply to a language with side effects.

[edit] Logic programming

Logic programming languages such as Prolog state and query relations. The specifics of how these queries are answered is up to the implementation and its theorem prover, but typically take the form of some sort of unification. Like functional programming, many logic programming languages permit side effects, and as a result are not strictly declarative.

[edit] Domain specific languages

Some well-known examples of declarative domain specific languages (DSLs) include regular expressions, CSS, and a subset of SQL (SELECT queries, for example). DSLs have the advantage of being useful while not necessarily needing to be Turing-complete, which makes it easier for a language to be purely declarative.

Many markup languages such as HTML, XAML, XSLT, SVG or other user interface markup languages are often declarative. HTML, for example, only describes what should appear on a webpage.

Some software systems now combine traditional user interface markup languages such as HTML with declarative markup that defines what (but not how) the back-end server systems should do to support the declared interface. Such systems, typically using a domain specific XML namespace, include abstractions of SQL database syntax or parameterised calls to web services using REST and SOAP.

[edit] Hybrid languages

Makefiles, for example, specify dependencies in a declarative fashion [3], but include an imperative list of actions to take as well. Similarly, yacc specifies a context free grammar declaratively, but includes code snippets from a host language, which is usually imperative (such as C).

[edit] See also

[edit] References

  1. ^ Lloyd, J.W., Practical Advantages of Declarative Programming 
  2. ^ Declarative language in The Free On-line Dictionary of Computing, Editor Denis Howe.

[edit] External links

Personal tools