On Tue, 20 May 2008, Arne VajhHj wrote:
Tom Anderson wrote:
The combination of default parameters and keyword arguments is a
simple, clean and convenient way of managing complicated argument
lists. Examples from python - subprocess.Popen:
No need for the routine author to write giant overloads, no need for
the caller to write loads of nulls or use a builder interface. It's a
simple and powerful way of managing complexity.
They could be added to the Java language.
But I don't know if they are worth the complexity.
We have already seen some complexity by adding variable
number of arguments.
I think the complexity is actually rather less than that - all that the
combination of defaults and keywords change allows is for callers to (a)
omit any number of parameters from the end of a call and (b) supply any
omitted parameters by keyword. The definition just involves writing some
defaults. There's no magic boxing of varargs into arrays or anything
like that. It's still more to know, of course, but it's not particularly
complex.
The one complex thing i can think of is inheritance. If i declare:
class Foo {
void bar(int i=23) ;
}
Clients can say:
Foo foo = ... ;
foo.bar(42) ;
foo.bar() ;
If i want to subclass Foo, do i have to override bar(int), bar(),
bar(int=default), or what?
PS: It would of course have to be something else than = to not break
existing code that passes a boolean expression.
Arne, please don't tell me you're confusing = and ==!
I am babbling nonsense. == would be a boolean expression. = is an
assignment. It is of course the assignment that is a problem.
the code does.