Matt Youell wrote: > > So perhaps sometimes in Perl we could say: > > my Dog $spot = undef; # Automagically knows to be a Dog ref instead > of a Dog object because of the undef. > if ($age > 12) { > $spot = new Doberman(); > } else { > $spot = new Corgi(); > } 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. I feel this discussion confuses multiple things: - Is a scalar an object or a reference to an object? - Must references to objects always be initialized at definition time? If feel that a scalar, even a typed one, is a reference to an object, not an object itself. undef is a reasonable initial value for a reference. In fact, supporting undefined references is necessary to build any complex data structure. Hence, I feel automatic initialization is the wrong thing to do. If we want a quick and easy way to initalize object references with a default-constructed object, we should have separate syntax to do so. What is the problem with: my Dog $spot; # Not initialized my Dog $spot = Corgi->new(); # Explicit construction and assignment my Dog $spot : default; # Call default constructor (and feel free to replace the attribute 'default' with any other you'd like) Hildo
- Re: RFC 171 (v1) my Dog $spot should call a c... Nathan Wiger
- Re: RFC 171 (v1) my Dog $spot should call... Michael Fowler
- Re: RFC 171 (v1) my Dog $spot should ... Nathan Wiger
- Re: RFC 171 (v1) my Dog $spot should call a const... Michael Fowler
- Re: RFC 171 (v1) my Dog $spot should call a const... Jonathan Scott Duff
- Re: RFC 171 (v1) my Dog $spot should call a c... Hildo Biersma
- Re: RFC 171 (v1) my Dog $spot should call... Piers Cawley
- Re: RFC 171 (v1) my Dog $spot should call a constructo... Hildo Biersma
- Re: RFC 171 (v1) my Dog $spot should call a const... Matt Youell
- Re: RFC 171 (v1) my Dog $spot should call a c... Michael Fowler
- Re: RFC 171 (v1) my Dog $spot should call a c... Hildo Biersma
- Re: RFC 171 (v1) my Dog $spot should call... Nathan Wiger
- Re: RFC 171 (v1) my Dog $spot should call... Matt Youell
- Re: RFC 171 (v1) my Dog $spot should call a const... Michael Fowler
- Re: RFC 171 (v1) my Dog $spot should call a const... Nathan Wiger
- Re: RFC 171 (v1) my Dog $spot should call a constructo... Piers Cawley
- Re: RFC 171 (v1) my Dog $spot should call a const... Nathan Wiger
- Re: RFC 171 (v1) my Dog $spot should call a c... Piers Cawley
- Re: RFC 171 (v1) my Dog $spot should call... Michael Fowler
- Re: RFC 171 (v1) my Dog $spot should ... Piers Cawley
- Re: RFC 171 (v1) my Dog $spot sh... Michael Fowler