HOME

TheInfoList




In
computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of , , and . Computer science ...
, declarative programming is a
programming paradigm Programming paradigms are a way to classify programming languages based on their features. Languages can be classified into multiple paradigms. Some paradigms are concerned mainly with implications for the execution model of the language, suc ...
—a style of building the structure and elements of computer programs—that expresses the logic of a
computation Computation is any type of that includes both al and non-arithmetical steps and which follows a well-defined model (e.g. an ). Mechanical or electronic devices (or, , people) that perform computations are known as ''s''. An especially well-know ...

computation
without describing its
control flow In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of Algor ...
. Many languages that apply this style attempt to minimize or eliminate
side effects In medicine, a side effect is an effect, whether therapeutic or adverse, that is secondary to the one intended; although the term is predominantly employed to describe adverse effects, it can also apply to beneficial, but unintended, consequences ...
by describing ''what'' the program must accomplish in terms of the
problem domain Problem solving consists of using generic or ad hoc methods in an orderly manner to find solutions to problems. Some of the problem-solving techniques developed and used in philosophy, artificial intelligence, computer science, engineering, ma ...
, rather than describe ''how'' to accomplish it as a sequence of the programming
language primitive In computing, language primitives are the simplest elements available in a programming language A programming language is a formal language comprising a Instruction set architecture, set of instructions that produce various kinds of Input/outp ...
s (the ''how'' being left up to the language's
implementation Implementation is the realization of an application, or execution of a plan A plan is typically any diagram or list of steps with details of timing and resources, used to achieve an Goal, objective to do something. It is commonly understood as ...
). This is in contrast with
imperative programming In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of Algori ...
, which implements
algorithm In and , an algorithm () is a finite sequence of , computer-implementable instructions, typically to solve a class of problems or to perform a computation. Algorithms are always and are used as specifications for performing s, , , and other ...

algorithm
s in explicit steps. Declarative programming often considers programs as theories of a
formal logic Logic is an interdisciplinary field which studies truth Truth is the property of being in accord with fact or reality.Merriam-Webster's Online Dictionarytruth 2005 In everyday language, truth is typically ascribed to things that aim to re ...
, and computations as deductions in that logic space. Declarative programming may greatly simplify writing parallel programs. Common declarative languages include those of database query languages (e.g.,
SQL SQL ( ''S-Q-L'', "sequel"; Structured Query Language) is a domain-specific languageA domain-specific language (DSL) is a computer languageA computer language is a method of communication with a computer A computer is a machine that can b ...

SQL
,
XQuery XQuery (XML Query) is a query and functional programming In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques ...
),
regular expression A regular expression (shortened as regex or regexp; also referred to as rational expression) is a sequence of Character (computing), characters that specifies a ''search pattern matching, pattern''. Usually such patterns are used by string-se ...
s,
logic programming Logic programming is a programming paradigm which is largely based on formal logic. Any program written in a logic programming language is a set of sentences in logical form, expressing facts and rules about some problem domain. Major logic prog ...
,
functional programming In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of , ...
, and
configuration management Configuration management (CM) is a systems engineering Systems engineering is an interdisciplinary field of engineering and engineering management that focuses on how to design, integrate, and manage complex systems over their enterprise life ...
systems.


Definition

Declarative programming is often defined as any style of programming that is not
imperative Imperative may refer to: *Imperative mood, a grammatical mood (or mode) expressing commands, direct requests, and prohibitions *Imperative programming, a programming paradigm in computer science *Imperative logic *Imperative (film), ''Imperative'' ...
. A number of other common definitions attempt to define it by simply contrasting it with imperative programming. For example: * A high-level program that describes what a computation should perform. * Any programming language that lacks
side effects In medicine, a side effect is an effect, whether therapeutic or adverse, that is secondary to the one intended; although the term is predominantly employed to describe adverse effects, it can also apply to beneficial, but unintended, consequences ...
(or more specifically, is
referentially transparent Referential transparency and referential opacity are properties of parts of computer programs. An expression (programming), expression is called referentially transparent if it can be Rewriting, replaced with its corresponding value (and vice-vers ...
) * A language with a clear correspondence to
mathematical logic Mathematical logic is the study of formal logic within mathematics. Major subareas include model theory, proof theory, set theory, and recursion theory. Research in mathematical logic commonly addresses the mathematical properties of formal sys ...
. These definitions overlap substantially. Declarative programming is a non-imperative style of programming in which programs describe their desired results without explicitly listing commands or steps that must be performed.
Functional Functional may refer to: * Movements in architecture: ** Functionalism (architecture) In architecture File:Plan d'exécution du second étage de l'hôtel de Brionne (dessin) De Cotte 2503c – Gallica 2011 (adjusted).jpg, upright=1.45, alt=Pl ...
and logical programming languages are characterized by a declarative programming style. In logical programming languages, programs consist of logical statements, and the program executes by searching for proofs of the statements. In a
pure functional language In computer science, purely functional programming usually designates a programming paradigm—a style of building the structure and elements of computer programs—that treats all computation as the evaluation of function (mathematics), mathematic ...
, such as Haskell, all functions are without side effects, and state changes are only represented as functions that transform the state, which is explicitly represented as a
first-class First class (or 1st class, Firstclass) generally implies a high level of service, importance or quality. Specific uses of the term include: Books and Comics * ''First Class'', List of Dandy comic strips, a comic strip in ''The Dandy'' (1983-1998 ...
object in the program. Although pure functional languages are non-imperative, they often provide a facility for describing the effect of a function as a series of steps. Other functional languages, such as
Lisp Lisp (historically LISP) is a family of programming language A programming language is a formal language In logic, mathematics, computer science, and linguistics, a formal language consists of string (computer science), words whose symbo ...
,
OCaml OCaml ( , formerly Objective Caml) is a general-purpose, multi-paradigm programming language Programming paradigms are a way to classify programming languages based on their features. Languages can be classified into multiple paradigms. S ...
and Erlang, support a mixture of procedural and functional programming. Some logical programming languages, such as
Prolog Prolog is a logic programming Logic programming is a programming paradigm which is largely based on formal logic. Any program written in a logic programming language is a set of sentences in logical form, expressing facts and rules about some ...

Prolog
, and database query languages, such as SQL, while declarative in principle, also support a procedural style of programming.


Subparadigms

Declarative programming is an
umbrella term In linguistics Linguistics is the scientific study of language, meaning that it is a comprehensive, systematic, objective, and precise study of language. Linguistics encompasses the analysis of every aspect of language, as well as the m ...
that includes a number of better-known
programming paradigm Programming paradigms are a way to classify programming languages based on their features. Languages can be classified into multiple paradigms. Some paradigms are concerned mainly with implications for the execution model of the language, suc ...
s.


Constraint programming

Constraint programming Constraint programming (CP) is a paradigm for solving combinatorial Combinatorics is an area of mathematics Mathematics (from Ancient Greek, Greek: ) includes the study of such topics as quantity (number theory), mathematical structure, ...
states relations between variables in the form of constraints that specify the properties of the target solution. The set of constraints is solved by giving a value to each variable so that the solution is consistent with the maximum number of constraints. Constraint programming often complements other paradigms: functional, logical, or even imperative programming.


Domain-specific languages

Well-known examples of declarative
domain-specific language A domain-specific language (DSL) is a computer languageComputer language is a formal language In logic, mathematics, computer science, and linguistics, a formal language consists of string (computer science), words whose symbol (formal), letters ...
s (DSLs) include the
yacc Yacc (Yet Another Compiler-Compiler) is a computer program A computer program is a collection of instructions that can be executed by a computer to perform a specific task. A computer program is usually written by a computer programmer in a ...
parser generator input language,
QML QML (Qt Modeling Language) is a . It is a language (similar to and ) for designing user interface–centric applications. Inline code handles imperative aspects. It is associated with , the UI creation kit originally developed by within th ...
, the
Make Make or MAKE may refer to: *Make (magazine), ''Make:'' (magazine), an American magazine and television program *Make (software), a computer-assisted software engineering tool *Make, Botswana, a small village in the Kalahari Desert *Make Architects, ...
build specification language,
Puppet A puppet is an object, often resembling a human, animal or mythical figure, that is animated or manipulated by a person called a puppeteer A puppeteer is a person who manipulates an inanimate object, called a puppet A puppet is an ...
's configuration management language,
regular expression A regular expression (shortened as regex or regexp; also referred to as rational expression) is a sequence of Character (computing), characters that specifies a ''search pattern matching, pattern''. Usually such patterns are used by string-se ...
s, and a subset of
SQL SQL ( ''S-Q-L'', "sequel"; Structured Query Language) is a domain-specific languageA domain-specific language (DSL) is a computer languageA computer language is a method of communication with a computer A computer is a machine that can b ...

SQL
(SELECT queries, for example). DSLs have the advantage of being useful while not necessarily needing to be
Turing-complete In computability theory Computability theory, also known as recursion theory, is a branch of mathematical logic Mathematical logic is the study of formal logic within mathematics. Major subareas include model theory, proof theory, set t ...
, which makes it easier for a language to be purely declarative. Many markup languages such as
HTML The HyperText Markup Language, or HTML is the standard markup language #REDIRECT Markup language In computer text processing, a markup language is a system for annotation, annotating a document in a way that is Syntax (logic), syntacticall ...

HTML
,
MXML MXML is an XML Extensible Markup Language (XML) is a markup language #REDIRECT Markup language In computer text processing, a markup language is a system for annotation, annotating a document in a way that is Syntax (logic), syntactically ...
,
XAML Extensible Application Markup Language (XAML ) is a declarative XML Extensible Markup Language (XML) is a markup language #REDIRECT Markup language In computer text processing, a markup language is a system for annotation, annotating a docu ...
,
XSLT XSLT (Extensible Stylesheet Language Transformations) is a language for transforming XML documents into other XML documents, or other formats such as HTML for web pages, plain text or XSL Formatting Objects, which may subsequently be converted to ...

XSLT
or other user-interface markup languages are often declarative. HTML, for example, only describes what should appear on a webpage - it specifies neither
control flow In computer science Computer science deals with the theoretical foundations of information, algorithms and the architectures of its computation as well as practical techniques for their application. Computer science is the study of Algor ...
for rendering a page nor the page's possible
interaction Interaction is a kind of action that occurs as two or more objects have an effect upon one another. The idea of a two-way effect is essential in the concept of interaction, as opposed to a one-way causal effect. Closely related terms are interac ...

interaction
s with a user. , some software systems 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#REDIRECT XML namespace XML namespaces are used for providing uniquely named Data element, elements and attributes in an XML document. They are defined in a W3C recommendation. An XML instance may contain element or attribute names from more than one ...
, may include abstractions of SQL database syntax or parameterized calls to web services using representational state transfer (REST) and
SOAP Soap is a salt (chemistry), salt of a fatty acid used in a variety of cleansing and lubricating products. In a domestic setting, soaps are surfactants usually used for washing, bathing, and other types of housekeeping. In industrial settings, ...

SOAP
.


Functional programming

Functional programming languages such as Haskell, Scheme, and ML evaluate expressions via function application. Unlike the related but more
imperative Imperative may refer to: *Imperative mood, a grammatical mood (or mode) expressing commands, direct requests, and prohibitions *Imperative programming, a programming paradigm in computer science *Imperative logic *Imperative (film), ''Imperative'' ...
paradigm of
Procedural programming Procedural programming is a programming paradigm Programming paradigms are a way to classify programming languages based on their features. Languages can be classified into multiple paradigms. Some paradigms are concerned mainly with i ...
, functional programming places little emphasis on explicit sequencing. For example, in Scheme, the order of evaluation of many kinds of sub-expressions is undefined or implicit. Instead, computations are characterised by various kinds of recursive
higher-order function In mathematics Mathematics (from Greek: ) includes the study of such topics as numbers (arithmetic and number theory), formulas and related structures (algebra), shapes and spaces in which they are contained (geometry), and quantities and t ...
application and
composition Composition or Compositions may refer to: Arts * Composition (dance), practice and teaching of choreography * Composition (music), an original piece of music and its creation *Composition (visual arts) The term composition means "putting togethe ...
, with explicit references to I/O and data appearing sparingly, and state mutation avoided or encapsulated wherever possible.


Hybrid languages

Makefiles, for example, specify dependencies in a declarative fashion, 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).


Logic programming

Logic programming languages such as
Prolog Prolog is a logic programming Logic programming is a programming paradigm which is largely based on formal logic. Any program written in a logic programming language is a set of sentences in logical form, expressing facts and rules about some ...

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.


Modeling

Models, or mathematical representations, of physical systems may be implemented in computer code that is declarative. The code contains a number of equations, not imperative assignments, that describe ("declare") the behavioral relationships. When a model is expressed in this formalism, a computer is able to perform algebraic manipulations to best formulate the solution algorithm. The mathematical causality is typically imposed at the boundaries of the physical system, while the behavioral description of the system itself is declarative or acausal. Declarative
modeling language A modeling language is any artificial language that can be used to express information Information is processed, organised and structured data. It provides context for data and enables decision making process. For example, a single customer ...
s and environments include Analytica,
Modelica Modelica is an , , multi-domain for modeling of complex systems, e.g., systems containing mechanical, electrical, electronic, hydraulic, thermal, control, electric power or process-oriented subcomponents. The free Modelica language is developed ...
and
Simile A simile () is a figure of speech A figure of speech or rhetorical figure is a word or phrase that entails an intentional deviation from ordinary language use in order to produce a rhetoric Rhetoric () is the Art (skill), art of pe ...
.


See also

* Comparison of programming paradigms *
Inductive programming Inductive programming (IP) is a special area of automatic programming, covering research from artificial intelligence Artificial intelligence (AI) is intelligence demonstrated by machines, unlike the natural intelligence human intelligence, ...
* List of declarative programming languages


References


External links

* Frans Coenen
Characteristics of declarative programming languages
1999. * Robert Harper.
What, If Anything, Is A Declarative Language?
2013.
There Is Such A Thing As A Declarative Language, and It’s The World’s Best DSL
2013. * Olof Torgersson

1996. {{Authority control Programming paradigms