Re: RFC 171 (v1) my Dog $spot should call a constructor implicitly
[email protected] ("Matt Youell")
| Newsgroups | perl.perl6.language.objects |
|---|---|
| Organization | Silicon Spike |
| Message-ID | <[email protected]> |
> Right now, the default behavior of perl is that un-initialized variables
> are automatically undef. It would be weird to have to do explicit
> assignment of an variable to say so.
You're right. And as another post mentioned, it's too much "magic". But It's
hard to come up with a comfortable syntax for doing both.
In C++, you've got two syntaxes for a reason: Objects either live on the
stack or the heap. So each syntax has a direct under-the-hood correlation to
the different ways of storing an object. I Perl, we don't really care where
the object gets stored so it's not as natural to make the distinction.
Perhaps the shift-on-the-fly usage could explicitly use a typeglob syntax
and declare it to be associated with Dog?
my Dog *spot;
> if ($age > 12) {
> $spot = new Doberman();
> } else {
> $spot = new Corgi();
> }
Matt