The syntax my Dog $brain declares that $brain is a Dog, and therefore everything that can be done with $brain has to be something that a Dog can do.

But then how come this works without error? (assuming that the method getCells is declared in Brain)

my Dog $brain = $dog->getBrain(); print $brain->getCells(); # prints 10 (see earlier example)
Are you just speaking theoretically? Or are you just refering to class fields and not methods? If that is so, then where is the real benefit in this? It seems I have to write code like this, to see any benefit.
print $brain->{cells}; # this prints: # No such pseudo-hash field "cells" in variable $brain of type Dog at +test.pl line 48.
And to me that defeats so much of what makes OO good (yes I know I am being a purist, but hey, its my opinion).

These are compile-time tests on the container $brain.

There is no runtime check in Perl 5 about whether the value put into $brain actually is a Dog.

So what is it checking then at compile time, if it cannot see the value I put in there and know its wrong? Is is only checking the underlying "hash" and access to that?

after all nothing stops someone from making a class that inherits from both Dog and Brain!

So it does not check the @ISA at all then either? Hmmm.

Now I know that perl (like LISP, Python and others) is a more dynamic langauge than say Java, C# or even Ada95. And I know that to add something like "strong" typing would make much of what makes perl so cool just about impossible. But you don't need "strong" typing to get the benefits of type "safety". Type inference in Standard ML works just fine and IMO is superior to "strong" typing (and much simplier to use too). It seems to me that maybe fields and its accompanying technology is not finished yet, and if it is, then its not what I am looking for.

-stvn

In reply to Re^5: use fields; # damnit by stvn
in thread use fields; # damnit by nothingmuch

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.