[xquery-talk] best practice for function design with many optional params

David Lee dlee at calldei.com
Thu Jan 26 04:12:13 PST 2012


Another common practice is to pass a sequence as the options.   Depending on
what values this has to take it may work well or not.
I've seen most commonly a sequence of strings naming boolean or enumerated
options.

-David

----------------------------------------
David A. Lee
dlee at calldei.com
http://www.xmlsh.org


-----Original Message-----
From: talk-bounces at x-query.com [mailto:talk-bounces at x-query.com] On Behalf
Of Michael Kay
Sent: Thursday, January 26, 2012 4:13 AM
To: talk at x-query.com
Subject: Re: [xquery-talk] best practice for function design with many
optional params


On 26/01/2012 08:13, Jakob Fix wrote:
> Hello,
>
> I'm confronted with the design of a function library where many
> functions have loads of optional arguments.
>
>
> I haven't really looked at maps (they are planned for XQuery 3.0 I
> think), what would their advantage be over the node approach? Any
> other ideas or pointers for more information?
>
Maps provide a good solution to this requirement, but sadly there has 
been resistance to getting them into the XQuery language in 3.0 
timescales so you may have to wait a little longer. (Or, as with 
grouping and updates, hope that your chosen implementors are ahead of 
the standards curve.)

If the optional parameters have values that are single strings, passing 
an element node with lots of attributes provides a suitable solution 
(it's equivalent to a map whose keys are QNames and whose associated 
values are strings). For more complex parameters this starts to break 
down, for example you can't pass nodes or function items this way. The 
other disadvantage of using nodes is that they carry a lot of baggage - 
identity, base URI, in-scope namespaces - which add cost and complexity 
without being in any way useful for this use case.

Michael Kay
Saxonica

_______________________________________________
talk at x-query.com
http://x-query.com/mailman/listinfo/talk



More information about the talk mailing list