User:Zomi86
Declarative programming has two different meanings, and both of them are in current use. For the first definition, declarative programming is a style of programming that concentrates on what to do, rather than how to do it. This contrasts with the imperative programming via imperative programming language which associates with languages like C, Fortran, and Pascal etc. Imperative programming is basically the programming that controls objects with writing instructions. The main difference between declarative programming and imperative programming is when imperative programs specify an algorithm to be run and achieve a goal; declarative programs specify the goal, not the implementation of the algorithm. HTML web pages are declarative, because they show what are there to make composition like text or image, but not how to display the pages.
For example, prolog is declarative, because the programmer sets the relationships without justifying how to calculate the answer. In Kowalski’s terms where algorithm equals to the composition of logic and control, the programmer gives logic, not necessarily the control. Another definition for declarative programming is if a program is written in a purely logic programming language or functional programming language is “declarative”. However, writing programs in a declarative style in an imperative programming language is possible.
Declarative programming language[edit]
Declarative programming language is usually refers to high-level languages such as Prolog and SQL, which can be used to control the behavior of a computer. However, declarative programming language is just a part of it. It has the same concepts with the declarative programming. Declarative programming language specifies a problem rather than figuring the solution out. There is an example of Prolog sample.
Example: prolog sample
/* Adapted from sample at: http://www.engin.umd.umich.edu/CIS/course.des/cis479/prolog/ This app can answer questions about sisterhood & love, e.g.: # Is alice a sister of harry? ?-sisterof( alice, harry ) #which of alice’s sisters love wine? ?-sisterof( X, alice ), love(X, wine) */ sisterof( X, Y ) :- parents( X, M, F ), female( X ), parents( Y, M, F ). parents( edward, Victoria, albert ). parents( harry, Victoria, albert ). parents( alice, Victoria, albert ). female( alice ) loves( harry, wine ). Loves( alice, wine ).
Examples[edit]
- JUnit : purpose of writing and running tests in Java programming language.
- SQL : Structured Query Language
- Lisp : Functional programming language that relates to declarative programming
- Prolog : Logic programming language that relates to declarative programming
- Oz : Constraint programming language that relates to declarative programming
References[edit]
- David Mertz. Advanced OOP: Declarative Programming and Mini-Languages 2001
- Marc Clifton. Comparing Declarative And Imperative Programming 2005
- June Jamrich Parsons & Dan Oja (2007). Computer concepts
External links[edit]
- Olof Torgersson. A Note on Declarative Programming Paradigms and the Future of Definitional Programming 1996
- Anoras.Declarative JavaScript programming 2004
- Frans Coenen. DECLARATIVE LANGUAGES 1999