[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

best practice for function design with many optional params

David Lee dlee at calldei.com
Thu Jan 26 07:35:59 PST 2012


  best practice for function design with many	optional params
Jakob Writes -->
---------------------------------
David, do you mean something along the lines of ('option-name-1',
'option-value-1', 'option-name-2', 'option-value-2', ...)? I would
think this would be quite hard to manage both on the calling side and
on the function side.

As my needs so far seem to be in the area of strings and integers, I
think I may go with the one element with attributes for each option
approach as suggested by Michael Kay. This seems to be a good
compromise with regard to verbosity, is reasonably similar to maps, so
a future update wouldn't be too complex; also I'd like to avoid
vendor-dependency where possible.

Thanks,
Jakob.

---------------------------------------------

Yes Jakob that was the approach was referring.
example:

mymodule:search(  doc("file.xml") , ( "case-sensitive" , "ascending" ) )

This might be equivalent to :

mymodule:search(  doc("file.xml") , 
	<options><case value='sensitive'><sort order='ascending'> </options>
)


I don't think either is particularly easier or harder to manage on the
caller or calling side.

The advantage of the simple list of strings is its a bit easier to write for
the caller, and is likely to be more efficient.  And the values don't have
to be strings, they could be any item type.
For example
    ( "max-lines" , 5 , "includes-element" , fn:QName( "foo" , "bar" ) )
However that then makes order important which in turn makes it harder to
parse.


The advantage of an options element is that its more structured, can contain
more complex data and you could even supply a schema for it if you wanted to
validate it at runtime.


<plug>
xmlsh for example uses both approaches, sometimes interchangeably.   Command
line scripts take a list of option values.  Sometimes its easier for the
script to parse these as an element so they can be converted vi the
"xgetopts" command - http://www.xmlsh.org/CommandXgetopts
</plug>

----------------------------------------
David A. Lee
http://x-query.com/mailman/listinfo/talk
http://www.xmlsh.org



_______________________________________________
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!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.