Faced with the alternative I'm glad Perl isn't typed much (just scalars et al).
Think about your snippets above for a bit and then be glad we don't have to worry about interfaces and up/down casting. Its because of this casting that we have so much verbosity in Java and C# in the first place.
Imagine something like this:
my $skip = (Dog) Animal->new;
or
my Dog $skip = Animal->new;
I think you hit the nail on the head with your:
my Dog @showdogs;
After all. Java has had to use Object with its collections to keep them generic. This leaves it to the programmer to *know* what to cast to when fetching the contents. Imagine this in Perl:
foreach my $dog(Dog @showdogs)
{
print $dog->bark(),"\n";
}
Eeeew. However, on the flip side perhaps some kind of autotesting at debug run time to see if an object can do what you want would be nice. So when you do the following:
method bark_at ($some_other_dog, $message)
You can specify debug code to run that uses isa() and can() on the references of your choice to test that you are passing the right stuff around.
However, I've only just thought of that and I don't know how valid or useful such an approach would be. What do you think? Example:
sub method bark_at ($some_other_dog, $message)
{
if(DEBUG)
{
die "Not valid class" unless is_obj_instance("Dog", $some_other_
+dog);
}
}
This function returning ok if the var is either an instance of Dog or can do all of Dogs methods.
However, in this case its more like an assertation. You could then also create your own $! if you wished.
I'm not convinced of the usefulness of this though.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.