>>>>> "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.

The "ref($proto) || $proto" code originally came from a guy who had
not done a lot of OO programming, and didn't completely understand it
apparently.  *I* was programming in Smalltalk in 1980.  *I* understand
the need for well-chosen method names.

So, while I cannot get "perltoot" removed from the docs, I'm
trying to do damage control to fix that problem.

There... does that help?  It's not about @ISA.  It's about proper
choice for method names.  $instance->new has too many meanings
to be a good name, ever.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

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

Reply via email to