I think that var-args parameters (as they are called in Java, my
primary language) are a cheap and easy way to make a method accept any
number of parameters. The problem is that it is not always easy to
understand, especially for new programmers. Also, when methods are
overloaded, var-args can cause a lot of confusion, especially in
dynamically typed languages. I think that the named optional
parameters are the best way to go.
someFunc(a, b, c...) {
for (d in c) {
// do something with the elements
}
}
someFunc(a, b, c, d, e, f) {
// do stuff
}
someOtherFunc(a, b, [List c = new List() ]) {
// c is a List, either use comments to convey this or a type in the
parameter
for (d in c) {
// do something with the elements
}
}
someOtherFunc(a, b, c, d, e, f) {
// do stuff
}
doStuff() {
// var-args
// which someFunc is being called?
someFunc('apples', 'bananas', 'cherries', 'blueberries',
'raspberries', 'blackberries');
// named optional parameters
// very clear which method is being called, also the List type in
the definition makes it
// easier for prgrammers understand what is to be done with it
someOtherFunc('apples', 'bananas', c: ['cherries', 'blueberries',
'raspberries', 'blackberries']);
}
Using named optional parameters only adds a few extra keystrokes,
depending on the length of the variable name, and it is MUCH clearer
what is going on.