develooper Front page | perl.perl6.language | Postings from June 2005

Re: construction clarification

Thread Previous | Thread Next
From:
Carl Franks
Date:
June 1, 2005 01:35
Subject:
Re: construction clarification
Message ID:
4f352aae0506010135166ecfe@mail.gmail.com
> It's *a* correct way. But redundant in this particular case.
> The universal new() would handle the one-argument call exactly the same
> as your overloaded new() does. Presumably, however, the one-argument variant
> would do something else as well.

Some people will need to call the constructor with a whole host of options:

my $foo = Foo.new(
  date => '2005-06-01',
  other => 1,
  params => 1);

For the typical case though, rather than forcing people to have to write
my $foo = Foo.new(
  date => '2005-06-01);

they should be able to write
my $foo = Foo.new('2005-06-01');

However, if I allowed the default 'new' to handle that case, then the
BUILD submethod has to be aware of that.
I thought it would be cleaner to 'document' the special case with a
seperate constructor, and also not require any special-case logic in the
BUILD submethod.

Is that really off the wall?

Carl

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About