Re: RFC 171 (v2) my Dog $spot should call a constructor implicitly

[email protected] (Michael Fowler)
Newsgroups perl.perl6.language.objects
Message-ID <[email protected]>
On Fri, Sep 01, 2000 at 05:23:27PM +0200, Slaven Rezic wrote:
> Often, there is the case that "my" is used before actually assigning a
> value to it. For example:
> 
>     my Foo $foo;
>     if ($cond1) {
> 	$foo = new Foo 1, 2, 3;
>     } else {
> 	$foo = new Foo 2, 4, 6;
>     }
> 
> If we have implicit constructors, will this cause unnecessary
> overhead, that is, calling the implicit constructor and then the real
> one?

Yes, so don't do that.  If you want optimization, I've been suggesting my
$spot : isa(Dog) (actually, I've been suggesting my $spot isa(Dog), which
was a typo):

my $foo : isa(Dog);
if ($cond1) {
    $foo = new Foo 1, 2, 3;
} else {
    $foo = new Foo 2, 4, 6;
}


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.