[xquery-talk] XQuery Style Conventions

Martin Probst martin at x-hive.com
Fri Oct 28 12:21:39 PDT 2005


> let $set1 := (3,2,1)
> let $set2 := (1,2,3)
> for $x in $set2
>      for $y in $set1
>      return
>          $x + $y
> As all for and let clauses simply add another variable and are equal  
> is that respect [...]

that's quite an interesting question. I generally prefer to keep them on
one level in smaller queries, but in certain cases one might argue for
indentation. In this example both the let statements simply bind a
value, but the for statements iterate. That's the difference.

So by indenting the for statement, one might express that this is (at
least conceptually) a n*m operation, iterating the whole cross product
of the two sets (btw: sets? there are no sets in XQuery ... except if
you specify "unordered").

> Personally, I prefer to keep them all at the same level to keep the  
> query compact (and it also fits well with the grammar).

Well, if you have queries going over hundreds of lines with >10
different for/let clauses, it is actually very helpful to get at least a
guess at which level of loop nesting you are. Otherwise you just have a
long sequence of statements on the same indentation level, so the
indentation doesn't give you any information. I like the style they


More information about the talk mailing list