drieux wrote:

> On Dec 19, 2003, at 1:16 PM, christopher j bottaro wrote:
>
> > i'm reading "Programming Perl" and i'm on the chapter about packages. it
> says
> > that packages and modules are very similar and that novices can think of

> > packages, modules, and classes as the same thing, but i wanna know
exactly

> > what the differences between packages and modules are (i'm a c++
> programmer,
> > i know what classes are).
> ...

>        # Our Stock Constructor
>         sub new
>         {
>                 my $type  = shift;
>                 my $class = ref($type) || $type;
>                 my $self = {};
>                 bless $self, $class;
>
>         } # end of our simple new

Hi drieux,

I have to question the constructor model above.  I was using it, in a pretty
much apish imitation of the model from the docs,  for modules until the
thread starting with:

Subject:      What is the best way to set options in a constructor
   Date:      Thu, 16 Oct 2003 15:35:22 -0400
   From:      Dan Anderson <[EMAIL PROTECTED]>
      To:     [EMAIL PROTECTED]

Message-ID: <[EMAIL PROTECTED]>

In which Randal set me straight on the actual implications of the
construct.  I had assumed that it was related to inheritance and was needed
to identify a new class as a subclass of its parents.  Randal set me
straight on this in the post:

Subject:       Re: What is the best way to set options in a constructor
       Date:   23 Oct 2003 07:14:47 -0700
       From:   [EMAIL PROTECTED] (Randal L. Schwartz)
         To: "R. Joseph Newton" <[EMAIL PROTECTED]>
         CC:   [EMAIL PROTECTED], Dan Anderson <[EMAIL PROTECTED]>


Message-ID:   <[EMAIL PROTECTED]>

[Randal]
...
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.
...
[/Randal]

It might be worth a trip to the archives to review this thread.

Joseph




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to