You're right in that C# and Java have a lot of duplication in this case. It'd certainly be nice to have to type what I mean only once. Here's some food for thought, though.
A good type-inferring system can gather, at compile time, the type of $dog in this construct:
my $dog = Dog->new();I'll probably write much, much more code that actually works with a Dog than code that instantiates a Dog. It seems more valuable to have the option to strictify your type checking these situations, where type inference really can't help:
method bark_at (Dog $some_other_dog, $message) { # horrible Perl6y pseudo-code print "$.name says to $some_other_dog.name, '$message'\n"; };
I wouldn't expect bark() to autoinstantiate a Dog object, but effectively it's declaring a lexical $some_other_dog that somehow conforms to Dog.
It'd also be weird to say:
class DogShow { my Dog @showdogs; }
and fill an array with placeholder Dogs. I might want to throw a robot dog in there, or a Puppy, or something that's not specifically a Dog.
In reply to Re: Fun with Typed Objects 1
by chromatic
in thread Fun with Typed Objects 1
by John M. Dlugosz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |