best practice for function design with many optional paramsDavid 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 http://x-query.com/mailman/listinfo/talk http://www.xmlsh.org -----Original Message----- From: http://x-query.com/mailman/listinfo/talk [mailto:http://x-query.com/mailman/listinfo/talk] On Behalf Of Michael Kay Sent: Thursday, January 26, 2012 4:13 AM To: http://x-query.com/mailman/listinfo/talk Subject: Re: 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 _______________________________________________ http://x-query.com/mailman/listinfo/talk http://x-query.com/mailman/listinfo/talk
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format