[Home] [By Thread] [By Date] [Recent Entries]
Roger, In my experience, declarative is typically used as a synonym for functional programming. True declarativeness basically means that you can unconditional specify the entire state of an application at any time for any initial given set of parameters. Declarative models are internally self consistent - there are effectively no side effects that can change the underlying state of the model without such side-effects being repeatable. A spreadsheet, for instance, is usually a declarative model - even when you have parametric changes in the model, repeating the input configuration of parameters will always reproduce the same resulting spreadsheet. Pure XQuery is a declarative language, with a couple of important caveats. If you have a static XML repository that you query against, then the resulting query result should be identical. However, there are a few XQuery functions (or extensions) that have side effects - now() and random(), for instance, where the same call to the function will result in different values. Additionally, In a non-static repository (as is typical of an XML database) especially one in which some form of XQuery Update Facility has been implemented, and where multiple entities can make changes to the database as a consequence, such systems become weakly imperative. That's why declarative and imperative programming shouldn't be taken as an absolute so much as a relative guideline. I find increasingly that it is often more useful to talk about explicit vs. implicit models. In a system with an explicit data model, you generally have reproducibility because you can see the state changes, and as such the model bindings to its associated presentation layer becomes obvious. In this model, randomness may exist, but the randomness is a functional model in which the same seed will always produce the same sequence of results, even if the specific function is a black box. In an implicit data model, on the other hand, not all of the parameters can be fully specified in the model. Imperative languages tend to encourage such implicit models (one of the real advantages of OOP was that it was at least a first stab in making such models explicit, though a great deal is still not fully specified). Imperative models are more complex to debug, because you have to use stochastic methods and try to employ a large enough cross section of potential use cases to determine that a given application is not likely to fail. In a declarative, or functional model, there should, in theory, be no way to actually move out of being internally consistent because the potential range of input is highly constrained - any input parameter that is invalid will invalidate the whole model, not just the specific property descriptor. In practice, this isn't always true, in part because its possible to underspecify or incorrectly specify the underlying data model dependencies, and in part because the more complex the model, the harder it is to fully specify it, especially when the constraint space extends across multiple domains of validation. However, by staying closer to a functional model, languages usually benefit by being far easier to debug and work with. In that regard, the XSLT program is clearly declarative - there are no formal side effects. Note that the fact that the XSLT is expressed in XML is something of a red herring - the XML representation of the XSLT follows a clearly defined schema, works within an explicit data model, and is simply a set of assertions. The XSLT program instance, however, is declarative for other reasons; you could in theory recast this in a language such as Scheme or Haskell and it would be just as valid and just as declarative (you could even use JavaScript, come to that). Another way of thinking about it as that declarative applications can clearly be used as filters on an incoming set of data to produce output, which in turn could be used as input for a successive state description. This means that any application can be fully described as a recursive process from a primogenitor state, and the full state space can thus be described completely at any given iteration based only upon the previous state and the filter. Imperative applications no longer have this reproducibility. At least that's my understanding - others with a decent functional programming background may be able to elucidate this more fully. Kurt Cagle Managing Editor http://xmlToday.org On Sun, May 31, 2009 at 6:23 AM, Costello, Roger L. <costello@m...> wrote:
[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] |

Cart



