Apparently, it’s the year of xquery. I’ve just started a large project at $WORK, of which XQuery is a fundamental piece. And I have to say I’m not so sure.
From what I’ve seen so far, there are good and bad bits to XQuery. The good bits are that it’s really flexible and very easy to pull apart large quantities of XML documents in ways in which it’s much, much harder with XSLT. I like the way XML fragments are treated as just another datatype, like E4X but done right. I also like the way that it’s built on XPath, as XPath rocks.
Sadly, there are quite a few more bad bits.
- The development environment leaves a lot to be desired (an eclipse plugin would be nice, as would vim1 or emacs2 syntax highlighting).
- XQuery itself is really verbose. There appears to be a lot of syntax, and the grammar is on the large side. This means that it’s really hard to pick up large bodies of other peoples code. Coincidentally like the stuff I’ve been dumped with.
- The spirit of the language is more like SQL than any procedural language. Yet it presents a veneer of procedurality, which fools you into thinking you can get away with things like “just throw an extra statement in”. It’s not that simple. Your XQuery code is returning a list of items3, so instead you have to insert your extra code as a previous item in the list. Essentially, this means you must end your extra code with a comma, instead of the expected semicolon or nothing. This continues to bite me.
- It’s still not a standard. “Nearly there now”, apparently. It’s beginning to sound like Perl 6…
- Namespaces continue to cause me much wailing and gnashing of teeth. In XQuery, there is a tendency to use quite a few of them as well. In fairness, this is more of an XML problem than an XQuery problem, but it’s really irritating to still be tripped up by having xpath not match because you’re not looking at a namespace by accident.
- The type system is a pain. XQuery may or may not be strongly typed, depending upon the code you’re using, the implementation, or the phase of the moon. It has had a tendency to get in the way, in all the stuff I’ve seen so far.
- For all its verbosity, the language itself is quite limited. I’ve been needing to use a lot of implementation-specific extensions in the work I’ve been doing. Particularly for things like updates.
- Oh, and whoever chose fucking smileys as the comment syntax needs to be shot. Now.
Having said all that, I think XQuery is still useful in the area I’m working in (large corpus’ of XML documents). Despite my rash of indignation, it’s proved a lot easier to deal with than our previous technology (flat files plus manually created indexes in an RDBMS plus Lucene for searching). It has a future. I just hope it develops quicker than it has so far.
1 That doesn’t suck, anyway, unlike xquery.vim.
2 I haven’t tried xquery-mode.el yet.
3 Except where it isn’t, e.g. defining functions.