[Date Prev]
| [Thread Prev]
| [Thread Next]
| [Date Next]
--
[Date Index]
| [Thread Index]
Re: [xml-dev] RE: Declarative programming requires a different mindset
- From: Dimitre Novatchev <dnovatchev@gmail.com>
- To: "Costello, Roger L." <costello@mitre.org>
- Date: Sun, 28 Mar 2010 17:52:54 -0700
On Sun, Mar 28, 2010 at 6:00 AM, Costello, Roger L. <costello@mitre.org> wrote:
>
> 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
^^^^^^^^^^^^
I think this is called a "relation". This remark applies to all
occurences of "relationship" below.
>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.
Decarative programs express *the knowledge* we have about a 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.
The computer doesn't create an execution plan -- the language processor does.
>
>
>
> 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.
Then how the computer solves the problem? I find the above statement incorrect.
>
>
>
> Declarative programs do _not_ tell what values to put into particular memory locations.
Nor do programs written in high-level imperative languages.
>
>
>
> Declarative programs do _not_ have variables that vary.
But may have identically named variables that have different values.
This only depends on the context. You haven't touched this important
concept: the context.
>
>
>
> Declarative programs do _not_ impose a particular execution plan on the computer.
But functional dependencies do define some more or less definite ordering.
Datatypes also may define specific ordering for their processing.
>
>
>
> /Roger
>
>
--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
I enjoy the massacre of ads. This sentence will slaughter ads without
a messy bloodbath.
[Date Prev]
| [Thread Prev]
| [Thread Next]
| [Date Next]
--
[Date Index]
| [Thread Index]