[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Declarative programming requires a different mindset

  • From: "Costello, Roger L." <costello@mitre.org>
  • To: "xml-dev@lists.xml.org" <xml-dev@lists.xml.org>
  • Date: Sun, 28 Mar 2010 09:00:59 -0400

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)

       Else

           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.

 

RECAP

 

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.

 

/Roger

 



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


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.