OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
RE: Declarative programming requires a different mindset

Hi Folks,


Below is a summary of our discussions. Please let me know where I err.


Declarative programming is a style of programming. You can write declarative programs in any programming language. However, some programming languages are designed to nudge you into the declarative mindset; programming languages that don’t have assignment statements fall into this category, e.g., XSLT.


To illustrate the declarative mindset, consider this:


    Area = Length * Breadth     (1)


It is describing a relationship between Area, Length, and Breadth. It is not an assignment statement or instruction. It is declaratively stating, “Here, this is a relationship that will be used in the program.”


Consider this:


   Carpet_Cost = Area * Price_Per_Unit     (2)


It is also a description of a relationship. It builds on top of the previous relationship. Thus, a larger concept (Carpet_Cost) is described using a smaller concept (Area). This is sometimes known as “functional composition.”


It is important to emphasize that (1) and (2) are descriptions; they are not assignment statements/instructions.


Area, Length, Breadth, Carpet_Cost, Price_Per_Unit are called variables. The term “variable” is used in the sense, “This is a symbol used to represent any (numeric) value.” Interestingly, this is also how mathematics uses the term.


Definite values may be given to variables; thus, if Length is given the value 6, Breadth is given 5, and Price_Per_Unit is given 2 then execution of this declarative program:


    Area = Length * Breadth

    Carpet_Cost = Area * Price_Per_Unit


Yields these results:

-    Area is 30

-    Carpet_Cost is 60


Relationships may apply to multiple things, e.g.,


    For each House_Room:

       Area = Length * Breadth

       Carpet_Cost = Area * Price_Per_Unit


Relationships may be conditional, e.g.,


    For each House_Room:

       Area = Length * Breadth

       If House_Room = Bathroom then

           Carpet_Cost = Area * (Price_Per_Unit * 1.2)


           Carpet_Cost = Area * Price_Per_Unit



The imperative mindset is to view these:


    Area = Length * Breadth

    Carpet_Cost = Area * Price_Per_Unit


as assignment statements -- blocks of computer memory are to be allocated and modified. The declarative mindset doesn’t think in those terms at all.


A programmer with a declarative mindset is likely to create quite different programs than a programmer with an imperative mindset.




Declarative programs describe the relationship of the output to the input.


Declarative programs describe the problem.


Declarative programs define reusable concepts; functions are typically the programming machinery used for defining concepts.


Declarative programs assemble concepts to create bigger concepts, i.e., functional composition.


Declarative programs allow the computer to devise its own execution plan, which may enable the program to be executed in any order or even in parallel.


Declarative programs do _not_ have instructions or statements.


Declarative programs do _not_ tell the computer what to do, i.e., how to solve the problem.


Declarative programs do _not_ tell what values to put into particular memory locations.


Declarative programs do _not_ have variables that vary.


Declarative programs do _not_ impose a particular execution plan on the computer.




[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS