| Declarative Programming |
Article Index for Declarative |
Articles about Declarative Programming |
Website Links For Declarative |
Information AboutDeclarative Programming |
| CATEGORIES ABOUT DECLARATIVE PROGRAMMING | |
| programming paradigms | |
|
According to one definition, a program is "declarative" if it describes ''what'' something is like, rather than ''how'' to create it. For example, web pages are declarative because they describe ''what'' the page should look like — title, font, text, images — but not ''how'' to actually display the page on a computer screen. This is a different approach from traditional Imperative Programming languages such as Fortran , C , and Java , which require the programmer to specify an Algorithm to be run. In short, imperative programs make the algorithm explicit and leave the goal implicit, while declarative programs make the goal explicit and leave the algorithm implicit. According to a different definition, a program is "declarative" if it is written in a Functional Programming language, Logic Programming language, or Constraint Programming language. The phrase "declarative language" is sometimes used to describe all such programming languages as a group, and to contrast them against Imperative Language s. These two definitions overlap somewhat. In particular, constraint programming and, to a lesser degree, logic programming, focus on describing the properties of the desired solution (the ''what''), leaving unspecified the actual algorithm that should be used to find that solution (the ''how''). However, most logic and constraint languages are able to describe algorithms and implementation details, so they are not strictly declarative by the first definition. Similarly, it is possible to write programs in a declarative style even in an imperative programming language. This is usually done by Encapsulating non-declarative details inside a library or framework. An example of this style is the use of reflection in the JUnit unit test framework, which allows unit tests to be registered with the framework merely by being defined. In a declarative program you write (declare) a data structure that is processed by a standard algorithm (for that language) to produce the desired result. When you write a web page for example, you declare what the page should look like in HTML , and the browser's procedural algorithm translates this into the pixels on the display. A declarative language, like all languages, has a syntax describing how the words in the language may be combined, and a semantics describing how sentences in the language correspond to the programs output. DOMAIN-SPECIFIC LANGUAGES One popular form of declarative programming is by using domain-specific languages (DSLs). "Domain" in this case refers to the "domain of discourse" — the subject matter that the language is intended to describe. For example, HTML is a domain-specific language, whose domain is web pages and hypertext. Other examples of DSLs are s can be seen as processing instructions). One drawback of DSLs is that they are not Turing-complete . That is, there are certain things they cannot do. Just as you cannot use a spreadsheet to send e-mail, you cannot use e-mail to calculate your bank balance. For this reason, DSLs are sometimes ''embedded'' inside a general-purpose programming language. This allows a programmer to use the DSL for problems that play to its strengths, and use the general purpose language for problems that are difficult or impossible in the DSL. Stand-alone DSLs — those not embedded in a general purpose language — are often easier to use than an embedded equivalent, since they avoid the added conceptual complexity imposed by the general purpose language. EXAMPLES Frameworks whose deployment has declarative programming aspects: Domain specific languages that support declarative programming:
Functional/logic/constraint programming languages that support declarative programming: tries to provide an exhaustive list. SEE ALSO
REFERENCES
EXTERNAL LINKS
|
|
|