"Say what you want, but not how you want it" (the phrase that describes declarative programming).
"The real world is not declarative. It has state (entities have internal memory) and concurrency (entities evolve independently."(Peter Van Roy & Seif Haridi)
Declarative programming vs. imperative programming
Declarative programming (also called "descriptive programming") is often contrasted with imperative programming:
In imperative programming, you specify in detail "how" you perform a process to achieve a result.
In declarative programming you specify "what" you want to achieve. To do this, you must first describe the knowledge you have of a given problem or field: the specific knowledge (the facts) and the generic knowledge (functions, rules, constraints, etc.). From this knowledge, several queries or problems can be posed to the system to obtain the corresponding results. These results are obtained by means of inference mechanisms or automatic calculations, without the need to specify any kind of process or control flow.
Types of declarative languages
Just as there are many imperative languages, there are also many declarative languages. However, the boundary between imperative and declarative languages is fuzzy. An imperative language may include declarative resources such as functions and rules. And a declarative language can include imperative resources. It is difficult to find "pure" declarative languages.
Declarative languages are associated with one or more programming paradigms. For example:
Functional and imperative: Lisp, Scheme, OcamL, Erlang.
Presentation of web pages: HTML.
Data structures: XML.
Characteristics of declarative programming
State independence.
A declarative expression preserves semantics regardless of the state of the executing system. And when the declarative expression is parameterized and invoked with the same arguments, it always returns the same result.
Referential transparency.
A declarative expression has referential transparency. That is, the expression can be replaced by its value without changing the meaning of the program.
Ubiquity.
The order of declarative expressions does not affect the meaning of the program.
Idempotence.
Replication of declarative expressions produces no effect.
Advantages of declarative programming
Declarative programming has several advantages over imperative programming:
Flexibility and generality.
Declarative programming is flexible. It is oriented to solve a set of problems associated with the specified knowledge base. In contrast, imperative programming is oriented to solve a single problem.
Superior semantics.
The semantic level of declarative programming is superior to that of imperative programming, since it uses generic expressions to encode generic knowledge. In contrast, imperative programming basically uses detail expressions.
This superior semantics translates into greater clarity, simplicity and expressiveness than in imperative programming, which tends to be rather cryptic in general. It also simplifies program development, including concurrent ones.
MENTAL and Declarative Programming
MENTAL is a multi-paradigm language. Different paradigms can be expressed using the same linguistic resources. Some paradigms (such as the logical paradigm) are essentially declarative, but in all paradigms declarative expressions can be used, which can be of the imperative, logical, functional, algebraic, etc. type.
Declarative programming is not really a programming paradigm, but a meta-paradigm or a programming style that can be used in all programming paradigms.
It is often stated that there is a fuzzy boundary between imperative and declarative programming. With MENTAL, this issue is clarified: there is no such (horizontal) boundary, but a dyadic (vertical) relationship between declarative programming and all programming paradigms, including the imperative paradigm.
In MENTAL declarative expressions are of several types:
Generic expressions. They produce inferences or automatic calculations. Thanks to generic expressions, many programming paradigms can be specified: logic programming, event-driven, constraint-driven, aspect-driven, agent-driven, etc.
Deferred substitutions (representations).
Substitution expressions in which relations of all kinds are established: logical, algebraic, etc.
(i^2 = -1) // definition of the imaginary unit (imaginary expression)
(a+i)^2 // ev. (a^2 + 2ai - 1)
i^3 // ev. −i
Bibliography
Agustí, Jaume (ed.). Segundo Congreso de Programación Declarativa (ProDe’93, Blanes). Consejo Superior de Investigaciones Científicas, 1993.
Cantone, Domenico; Omodeo, Eugenio. Set Theory for Computing: From Decision Procedures to Declarative Programming with Sets. Springer, 2001.
Carpio Cañada, José; Aranda Corral, Gonzalo Antonio; Marco de la Rosa, José. Programación declarativa. Servicio de Publicaciones - Universidad de Huelva, 2011.
Delgado Kloos, Carlos. Programación declarativa. Fundación Rogelio Segovia para el Desarrollo de las Telecomunicaciones, 1994.
Flach, Peter. Simply Logical: Intelligent Reasoning by Example. John Wiley and Sons, 1994. Disponible online.
Lloyd, J.W. Declarative programming in Escher. University of Bristol, 1995.
Lloyd, J.W. Practical advantages of declarative programming. In Joint Conference on Declarative Programming, GULP-PRODE'94, 1994.
Padawitz, Peter. Deductive and Declarative Programming. Cambridge University Press, 1992.
Scott, Michael L. Programming Language Pragmatics. Morgan Kaufmann, 2005.
Van Roy, Peter; Haridi, Seif. Concepts, Techniques, and Models of Computer Programming. MIT Press, 2004.