[xquery-talk] Top N Most Common Mistakes
mike at saxonica.com
Thu Aug 2 12:13:42 PDT 2007
> Yes, what are they? What are the most common mistakes that
> novice, experienced a like, do when writing XQuery queries?
Hard to tell because the number of XQuery questions I see is perhaps 5% of
the number of XSLT questions. Does this mean XQuery users have fewer
problems? Somehow, I don't think so.
It depends of course on where you are coming from and what environment you
are working in. If you're trying to run XQuery in a hybrid SQL/XML database
then you've got a whole load of different issues, like working out how many
backslashes to put in front of a quote charater.
XQuery users face most of the same learning issues as XSLT users -
namespaces, character encoding, understanding that you're dealing with a
tree rather than with lexical markup, side-effect-free programming,
recursion, etc. There are fewer opportunities for making mistakes connected
with context, because XQuery relies far less on context. But it's still easy
to get path expressions wrong either because the XML vocabulary is very
complex or because you don't know what you're doing. You still get the
people who imagine that because variables are flagged with a "$" sign they
must work by textual substitution. And of course XQuery users don't have to
learn templates and import precedence - though when they start to tackle
harder problems they have to learn how to get by without them. That's
tougher for real programmers than for script-kiddies who don't know what
Some coding patterns are easier in XQuery than XSLT, notably joins, and some
are harder, notably handling of mixed content and recursive-descent
transformations. Value-based grouping is a little easier than XSLT 1.0,
because of distinct-values(); but much harder than XSLT 2.0; and positional
grouping requires a very high level of programming competence.
Yes, operator precedence can certainly trip you up on occasions. I still
find it very hard to find a visual layout for code that makes it readable,
because of the mixture of syntactic styles in the language.
Perhaps the most common trivial mistake is to forget curly braces. Knowing
when you need a comma between direct element constructors and when you don't
can also be bewildering.
When people get beyond the 20-line student exercise level, I think the
restrictions on module imports will prove quite troublesome. But I don't see
many people doing multi-module queries on a big scale yet.
More information about the talk