"Randal L. Schwartz" wrote:

> >>>>> "R" == R Joseph Newton <[EMAIL PROTECTED]> writes:
>
> R> "Randal L. Schwartz" wrote:
> >> >>>>> "Dan" == Dan Anderson <[EMAIL PROTECTED]> writes:
> >>
> Dan> my $class = ref($proto) || $proto;
> >>
> >> Don't do this!
> >>
> >> <http://www.perlmonks.org/index.pl?node_id=52089>.
>
> R> Hi Randal,
>
> R> Read the article, and it percursor thread.  I'm still a little mystified as to
> R> what you find offensive there.  Perhaps one should be aware of the contents, if
> R> any, of @ISA, before writing the new method.  It doesn't always work that way,
> R> though, and having a flexible [and standardized] constructor does not seem to do
> R> any harm.  Is there some potential harm you see?
>
> Sorry you missed the point then.
>
> The point is that
>
>         $instance->new
>
> could mean either "clone", or "make one of the same class as".  You
> don't need it for "make one of the same class as", because you've got:
>
>         (ref $instance)->new
>
> to do that explicitly.  And if you really wanted that to do clone,
> CALL IT CLONE, don't call it ->new.
>
> It obscures more than it clarifies, and hence is a *bad* name
> for an instance method.
>
> And because it's a bad name for an instance method, it should
> not respond as an instance method.  That simplifies the "standard
> constructor immensely", to something like:
>
> sub new {
>   my $class = shift;
>   my $self = { ... };
>   other fixups
>   return bless $self, $class; # return is optional here
> }
>
> This makes your code both clearer, and faster.

Got it.  Thanks.  You know, I never would have imagined anybody trying to use a
constuctor to clone, except perhaps by passing an object reference in as an argument.
I had asumed that it had something to do with importing parent classes.  Thanks for
clearing that up.  I guess I'll do some inheritance experiments to see how the
constructor works without that construct.

Joseph



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to