You are on page 1of 4

Declarative programming:-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.[3] Common declarative languages include those of regular expressions, logic programming, and functional programming.

[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:

A program that describes what computation should be performed and not how to compute it Any programming language that lacks side effects (or more specifically, is referentially transparent) A language with a clear correspondence to mathematical logic.[4]

These definitions overlap substantially.

[edit]Subparadigms
Declarative programming is an umbrella term that includes a number of better-known programming paradigms.

[edit]Constraint

programming

Main article: Constraint programming In constraint programming, relations between variables are stated in the form of constraints, specifying the properties of a solution to be found. The set of constraints is then solved by giving a value to each variable so that the solution is consistent with the maximum number of constraints. Constraint programming is often used as a complement to other paradigms: functional, logical or even imperative programming.

[edit]Domain-specific

languages

Main article: Domain-specific language

Some well-known examples of declarative domain specific languages (DSLs) include Cascading Style Sheets (CSS), regular expressions, 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, MXML, SVG, XAML, XSLT or other user interface markup languages are often declarative. HTML, for example, only describes what should appear on a webpage and does not specify the possible interactions with it. 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 usingrepresentational state transfer (REST) and SOAP.

[edit]Functional

programming

Main article: 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, such as Scheme, OCaml, Standard ML, and Unlambda, 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]Hybrid

languages

Makefiles, for example, specify dependencies in a declarative fashion,[5] 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]Logic

programming

Main article: 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.

ADVANTAGES
Smaller Programs

Programs made with a declarative language are often smaller than ones made with an imperative language. This is because you need to use less code to accomplish a goal. For example, in Prolog you can write a one-line fact that defines the current month, then use one more line to ask what month it is in the program. In an imperative language such as C++, you create and initialize a variable, then use a multi-line "if" statement block to check the value of the variable, and program the conditional outcomes.

Reusable Code

The code that defines how to accomplish a task is actually built into the programming language or in the computer itself. For example, an SQL "SELECT" command tells a database that you want it to return all records in a table based on some criteria. You don't care how it gets those results to you. However, SQL knows the details, saving you the time and effort of having to write code yourself that is already a part of the language's functionality.
Sponsored Links

Secure Software
Nullcon Conference on 26th-29th Sep Workshop and Training at New Delhi. www.nullcon.net

No Scripts

In imperative programming, you write a block of code, called a script, which defines how to get a result, whether it's a calculation or a list of steps. Declarative programming languages do not need scripts to define how the program should relate one clause to another. In a programming language such as Prolog, you define relationships using facts and rules, and the program knows and can determine the flow of a program by itself.

Ease of Use

Due to the simplistic nature of a declarative language, people new to programming can pick up the basic concepts of the paradigm quickly and write a program with ease. Using HTML, you can quickly learn how to design a simple Web page that includes items such as links, images and text, as all of these tags tell the browser what you want the page to look like and how to achieve that look.

DISADVANTAGES ??

You might also like