in reply to Re^4: use fields; # damnit
in thread use fields; # damnit
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)
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.
my Dog $brain = $dog->getBrain();
print $brain->getCells(); # prints 10 (see earlier example)
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).
# this prints:
# No such pseudo-hash field "cells" in variable $brain of type Dog at
+test.pl line 48.
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.