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

Michael Kay mike at saxonica.com
Thu Jan 26 16:00:54 PST 2012


Jim Fuller>I think in any programming language, its kind of a 'bad 
smell' when a function has a very long signature ... are you sure all 
these options are intrinsic to your function

I think there's a difference between "having lots of options" and 
"having a very long signature". In languages where functions always have 
positional arguments, the challenge is to define a function signature 
that accepts lots of options without requiring lots of positional 
arguments, and that's what we are discussing here. Using a map argument 
is essentially a workaround for the fact that the language does not 
offer named parameters on calls.

I can think of plenty of cases where having lots of options is perfectly 
respectable. For example I can think of at least a dozen options one 
might want to specify to the deep-equal() function. It's only because 
XQuery doesn't provide a convenient way of providing such options that 
they aren't actually available.

(The regular expression functions, incidentally, provide options through 
the flags argument as a set of boolean options each represented by one 
letter in a string: it's a crude mechanism, but it works.)

Michael Kay
Saxonica


More information about the talk mailing list