[xquery-talk] best practice for function design with many optional params
james.fuller.2007 at gmail.com
Thu Jan 26 21:11:42 PST 2012
On Fri, Jan 27, 2012 at 1:00 AM, Michael Kay <mike at saxonica.com> wrote:
> 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
sure, I think we are in agreement
> 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.
sure, perhaps 'bad smell' was too strong a term, but in general I
think one should avoid very long signatures if possible
> (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.)
I am used to this kind of thing but I think we are all in agreement
that maps would have been a nice thing.
More information about the talk