I would say that in almost all cases, the first form is more readable
but probably exhibits the same performance.
A special case is when making a lot of trips to a variable that
represents a node, it can be faster to construct an in-memory element
with just the relevant data. (for example- element holder { $n/x, $n/y
}) We saw this when attempting to implement efficient group-by behavior
on large data sets. It seems like this is an implementation quirk and
maybe someone from ML can provide more insight.
-Matt
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of
> Tim Finney
> Sent: Wednesday, February 28, 2007 5:25 PM
> To: [email protected]
> Subject: [MarkLogic Dev General] Which is better?
>
> I use this idiom quite often:
>
> for $node in $thousands-of-nodes
> let $n := $node/path/to/@n
> return
> if ($n)
> then $n
> else do-something-else()
>
> But one can say this instead:
>
> for $node in $thousands-of-nodes
> return
> if ($node/path/to/@n)
> then $node/path/to/@n
> else do-something-else()
>
> As a general rule, is it better to declare a variable and use
> it in the if test and then clause, or to use a path in both
> places? Maybe there is a better idiom?
>
> Best
>
> Tim Finney
> Programmer
> University of Virginia Press
>
> _______________________________________________
> General mailing list
> [email protected]
> http://xqzone.com/mailman/listinfo/general
>
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general