• << Return Home
  • XSLT:Blog[@author = 'M. David Peterson']/Main: XML, XSLT, XQuery, and Declaritve Programming Archives
              • December 28, 2004

                A very nice explanation to the question of "Are XSLT and XQuery declarative?"

                To keep you from rolling your eyes or believing that in some way the poster of this comment to xml-dev is the only persons opinion I deem as important in this world I am simply going to use the initials MC as a suggestion to who posted this reply to the question:

                In a recent post to xml-dev Michael Rys answers the following question:

                "...Except that, XSLT is a functional programming language, and from what I can see of XQuery, it has a lot of looping. SQL is a declaration of, well not my lexicon, a desired result set in the terms of relational calculus.

                Are XSLT and XQuery declarative?"

                In which the poster "MC" Michael Rys stated:

                NOTE: Before you click that link... no, don't do it... STOP!!!! Hmmm... well, for those of you still with us please visit this paper by Dimitre Novatchev to further your understanding as to whether or not XSLT can even really be considered a true functional-language... Ok, you're back... now aren't you inherently glad that you followed my first advice and chose instead to enrich your understanding of functional-programming and XSLT? Feel free to click ahead at anytime you feel comfortable in doing so (I'm like a human valium when I wanna be, huh?! ;):D)

                "Both XSLT and XQuery are declarative. The FLWOR in XQuery is not a loop but a declarative iterator like the SELECT/FROM/WHERE in SQL or the apply in CM LISP.

                The main advantages of declarative languages are that you need to write less code for achieving a given function point, you operate on a large set of data at once, and that an execution engine can apply rewrites (if they are based on an algebra) and other optimizations to execute it more efficiently.

                Procedural languages are much harder to optimize due to their often lower expressivness at the operator level, their one-item at a time processing model, and their tendency to allow and sometimes encourage programming by side-effect.

                Furthermore, declarative languages are less brittle towards changes in the physical design than APIs are. For example, an implementation that uses a push-parser and wants to move to a pull-based model has to completely change at the programming level, whereas a program using a declarative language does not notice any changes below.

                XMLReader/TRAX/SAX etc are APIs that mostly promote a one item at a time processing model and are embedded in mainly procedural languages. XQuery/XSLT and at least the XPath parts of the different APIs are declarative.

                Is there a place for both? Yes. Declarative languages often come with extensive support frameworks for the optimizers which may be overkill in a situation where small, hardcoded logic is needed. And you need them to build the declarative processing engines :-). But in general I have to agree with Dana that good XSLT and XQuery engines (or other higher abstractions) OVER TIME should offer enough benefit of scale, performance and ease of use, that the majority of implementers do not need to revert to the lower-level APIs.

                Note that this does not preclude that such engines will need optimization hints (e.g., to achieve 10% better streaming performance), physical design decisions etc.; or that one context decides to implement a predictable subset (see Arpan's posting).

                Best regards

                Michael

                PS: One of the big short-comings of hierarchical databases was that they basically offered only navigational APIs and were brittle towards physical optimizations and schema changes. XML is often compared to hierarchical databases (in the negative sense), but these people don't realize that declarative languages such as XQuery or XSLT and the ability to choose different physical designs and optimizations(including streams) without impacting the logical level make it much better than hierarchical databases and much closer to so-called non-first-normal-form (or NF2) models..."

                NOTE: To give proper credit the above came from Michael Champion Rys, today's official <XSLT:Blog /> Horder of the Most Posts or Comments award. Don't fret, maybe tomorrow you will be the victor in receiving this newly created but coveted none-the-less "HotMPoC" (correctly pronounced hottempock) award. I think I need to make some sort of certificate or something...

                Posted by m.david at 04:53 PM | Comments (2) | TrackBack

          • © 2005 :: <XSLT:Blog/> (xsltblog.com) is a product of M. David Peterson and FunctionalX Consulting. See Licensing Info Below.
          • Except where otherwise noted, this sites content and source code is licensed under the Attribution License from Creative Commons.