[MarkLogic Dev General] Which is better?

Griffin, Matt MGriffin at nerac.com
Wed Feb 28 16:34:38 PST 2007


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: general-bounces at developer.marklogic.com 
> [mailto:general-bounces at developer.marklogic.com] On Behalf Of 
> Tim Finney
> Sent: Wednesday, February 28, 2007 5:25 PM
> To: general at xqzone.marklogic.com
> 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
> General at developer.marklogic.com
> http://xqzone.com/mailman/listinfo/general
> 


More information about the General mailing list