Re: passing a Factory to a method to create a generic instance
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
---910079544-558251550-1211368686=:3807
Content-Type: TEXT/PLAIN; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8BIT
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:
http://docs.python.org/lib/node528.html
And csv.reader, which can take a bunch of formatting parameters:
http://docs.python.org/lib/csv-contents.html
http://docs.python.org/lib/csv-fmt-params.html
Having defaults means that in the simple case, you can do:
rows = csv.reader(somefile)
But that if you do want to apply some tweaks, you can do:
rows = csv.reader(dialect="excel", skipinitialspace=True,
lineterminator="\t")
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? Can i inherit the default? Python is untyped,
so this is a non-issue - a message gets sent, a method gets located, or
else there's an error. In java, though, we have to have rules about this.
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 ==!
tom
--
I need a proper outlet for my tendency towards analytical thought. --
Geneva Melzack
---910079544-558251550-1211368686=:3807--