XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
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: [xml-dev] RE: Declarative programming requires a different mindset

I'm coming somewhat late to the party here - but this is a topic dear to my heart.
 
My first love in programming languages is Prolog.  Assertions, clauses, predicates, recursion and goal setting along with constraints. Constraints are so so important in optimizing the goal setting and guiding the execution path.  Having the compiler tell you something is non-deterministic is also very cool!  I can write this stuff with my eyes closed - and it tends to work mostly first time - don't ask me how or why - its just sorta the way your brain is wired - possibly has something to do with the fact that I play chess to a pretty high level too - you can just "see" these patterns.  Getting paid to do this almost feels like cheating?!
 
So - I never realized how closely xslt can resemble this paradigm too - until this past year and all the work that has gone into developing the CAM toolkit using xslt - some 30,000 lines currently.
 
It's kinda good news bad news however - because I've also found that unless you speak fluent xslt - this stuff can be pretty opaque to the average casual reader of the code - who have little to no inkling of how the magic is happening.  This stuff is also non-trivial to document in traditional procedural sense, because that does not make sense either.  The code itself to the initiated is of course completely transparent and easy to follow (well mostly hopefully!).
 
Such are the burdens we carry.  When I first learned Prolog I remember seeing that programmers should be taught in this language FIRST before any other - because it forces you to approach any problem solving with a better paradigm - always considering the "other" condition in any decision clause - rather than simple "if then" logic.  And of course using recursion as your go to loop logic.  But then the best feature is the ability to have predicates with late binding patterns - e.g. solve(in,_,_,out)
 
You just don't get the sense of the power of this paradigm when you have been spoon fed Java and VisualBasic!?!
 
One mans elixor is of course another mans poison!
 
DW
 
 
-------- Original Message --------
Subject: Re: [xml-dev] RE: Declarative programming requires a different
mindset
From: Dimitre Novatchev <dnovatchev@gmail.com>
Date: Sun, March 28, 2010 8:52 pm
To: "Costello, Roger L." <costello@mitre.org>
Cc: "xml-dev@lists.xml.org" <xml-dev@lists.xml.org>

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.

_______________________________________________________________________

XML-DEV is a publicly archived, unmoderated list hosted by OASIS
to support XML implementation and development. To minimize
spam in the archives, you must subscribe before posting.

[Un]Subscribe/change address: http://www.oasis-open.org/mlmanage/
Or unsubscribe: xml-dev-unsubscribe@lists.xml.org
subscribe: xml-dev-subscribe@lists.xml.org
List archive: http://lists.xml.org/archives/xml-dev/
List Guidelines: http://www.oasis-open.org/maillists/guidelines.php



[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