in reply to Feedback: Strongly-typed "Pascal records" module

Yes, there are other things like that, that provide error checking on hash keys. There are pseudo-hashes. There's some stuff in Conway's book on OO Perl. There's the use of accessor functions instead of direct hash access. There's Tie::SecureHash mentioned in the 5.8 docs as a replacement for pseudo-hashes for implementing the base/fields modules.

I don't know what does the same kind of type checking you have (as opposed to just allowed keys), but I've read about that kind of thing from time to time.

Perl doesn't require strict typing. In that respect it's more like Smalltalk than C++. That is, an object doesn't necessarily have to be of a particular class (or derived class) to "fit". It just has to have all the right methods available.

  • Comment on Re: Feedback: Strongly-typed "Pascal records" module

Replies are listed 'Best First'.
Re: Re: Feedback: Strongly-typed "Pascal records" module
by pg (Canon) on Jan 01, 2003 at 21:06 UTC
    Just want to extend what you said in your last paragragh.

    I think it is useful and helpful to extract the concept of "interface" out from the concept of "class". Although Perl does not clearly support the concept of interface, not to say pure interface, but there are lots of evidence that, one can actually mimic it to a certain level, and Perl is doing this either consciously or subconsciously. (It is simply impossible for you not to be influenced by the world around you, especially those beautiful things)

    A very good and typical example is Tie::Hash. When you extend Tie::Hash, Perl does not care how you implement it, what data structure you use etc., as long as you implement certain interface methods, like DELETE, FETCH etc., everything would be perfect as far as Perl concerns.

    I would expect those conceptual stuff would become much more clear in Perl 6.

    Update: aspen, You can regard my reply as a discussion with John, about some interesting points he brought up. It is not directly related to your post, and I didn't judge what you posted. ;-) have a Happy New Year.
Re: Re: Feedback: Strongly-typed "Pascal records" module
by aspen (Sexton) on Jan 01, 2003 at 21:37 UTC
    Replying to both John M. Dlugosz and pg, you are right about the variety of related hash-checking and field-checking pragmas and modules that exist. The particular goal here was about type checking during the assignment of a value to one of an object's instance variables. The "type" of the assigned value must match the "type" expected for that key. When following general OO rules this means checking the module author's action, since non-authors are generally supposed to use module-author accessor methods to modify instance data. (Though Tie::Record will check extra-package assignments as well.)

    It wasn't my particular goal to validate/examine whether a derived module was validly implementing it's parent's (or parents') interface. Rather, enable Perl to say to me "Yo, coder, I don't think you did what you meant to do. Isn't this particular object's xxxx instance variable supposed to hold Foo::Bar objects and not Bar::Foo objects!?"

    It ensures my mis-assignment to an instance variable gets noticed at its source instead of (much) later when its effect finally shows up.

Re: Re: Feedback: Strongly-typed "Pascal records" module
by Anonymous Monk on Jan 01, 2003 at 20:38 UTC
    pseudo hashes are deprecated. If you don't know what they are, don't bother learning. If you do, figure out where you used them and rewrite...