http://www.perlmonks.org?node_id=219973


in reply to Re: Yet Another Perl Object Model (Inside Out Objects)
in thread Yet Another Perl Object Model (Inside Out Objects)

I want access to those hashes!

Yeah, I thought about that. I figured that it more or less violated the flywieght pattern that Abigail was using, so I could justify keeping that for an update or later version. :-) Patches welcome.

As for the bug that you guys encountered, one thing that can be helpful is to prevent modules from being updated by using file security. That way unexpected changes arent introduced into a running system. I agree with you that this type of error is unusual however.

--- demerphq
my friends call me, usually because I'm late....

  • Comment on Re: Re: Yet Another Perl Object Model (Inside Out Objects)

Replies are listed 'Best First'.
Flyweights - different meaning in perl?
by adrianh (Chancellor) on Dec 15, 2002 at 14:47 UTC
    Yeah, I thought about that. I figured that it more or less violated the flywieght pattern that Abigail was using...

    I'm a little confused about why people keep referring to Abigail-II's object implementation as being based on the flyweight pattern.

    According to my copy of Design Patterns a flyweight pattern is:

    Using sharing to support large numbers of fine-grained objects efficiently

    The example they use in the book is character objects in a word processor. Obviously having a separate object for each input character is going to have a huge resource overhead. So, instead, you create a single pool of objects - one per character - and use the same object for every instance of "a", etc.

    Another example from my own experience in perl was when I worked on a project that had a large number of database tables that consisited of static data - lookup tables of info.

    Rather than spend a lot of time doing a SELECT every time I needed the info I slurped up the entire table, made a pool of static objects, and served up the appropriate one on request.

    To be useful flyweights can't have extrinsic state - no context dependant information - just intrinsic state.

    So I can't see any relation between flyweights and inside out objects. Does the term mean something different in the perl world? If so - what, and why would accessing the hashes directly violate it?

      adrianh asked me to comment on this thread.

      Yes, the "flyweight objects" described in "OO Perl" are structurally capable of being used as Flyweight Objects (in the Gang of Four sense).

      No, the example code shown in "OO Perl" doesn't implement the full flyweight metaphor. Specifically, it doesn't include the necessary constructor code to check if an object already exists (in the logical sense) and so avoid reinstantiating it in that case.

      In other words, both sides of this debate were essentially correct. Isn't postmodernism wonderful? ;-)

      Why did I stop short of explaining the full technique? Well, even though the changes required to the constructor code would have totalled only a few lines, explaining the concept underlying the full pattern would have required several additional pages of exposition, and I was already 200 pages over my contract limit as it was.

      Besides, it was (and still is) my assessment that the most significant application of this type of class is in providing robust, yet maintainable, encapsulation. In Perl at least, its other ability -- to optimize away duplicate value-type objects -- is much less commonly needed.

        would have required several additional pages of exposition, and I was already 200 pages over my contract limit as it was.

        /me patiently waits for the directors cut to be released...

        ;-)

        --- demerphq
        my friends call me, usually because I'm late....

        Thanks for the comments

        In other words, both sides of this debate were essentially correct. Isn't postmodernism wonderful? ;-)

        <group hug>

        :-)

      I've studiously avoided the term "flyweight objects" as I have only ever seen it here and didn't really understand its meaning. I'll stick to "Inside-out" which only has meaning in perl terms as far as I am aware.

      With regard to the example you describe, that may have made some sense in the world of 8-bit chars as you only need a pool of 256 object, but in the world of UCS, it becomes excessive I think.

      Actually, I say only 256 objects, but even that doesn't make any sense to me. It might make sense in a pure OO, conceptual sense to have a seperate object for each char, but it my view its a very strange thing to do.

      There are to my way of thinking only two things you can do with a char.

      • Use it. Ie. give it to some other object as a parameter.
        Eg. somestring.append('A'); or somestring.append( somechar );
      • Or ask it for its ordinal value.
        Eg. 'A'.ord(); or somechar.ord();

      So even if you want to represent it at the language level as an object, in terms of what the compiler or interpreter would actually manipulate, it's just a number.

      Unless I'm missing something, which is quite possible because I often do, the idea that the compiler/interpreter would manipulate a pointer to an object or worse, a handle to an object at the binary level is simple crazy?

      Can you see a reason for having an object to represent each char? I mean, if your are going to allow attributes to be applied to individual chars (color, size, whatever), then pooling the objects isn't going to work because I wouldn't be able to have a red 'A' and a green 'A' at the same time.

      I can see the need for being able to maintain and manipulate attributes for aggragations of chars. This string is ascii, that sting is EBCDIC, but doing this at the char level does make any sense (to me). If you could do it, then you could create aggregate strings of mixed ascii and EBCDIC and then what happens when you want to compare string 'T{ascii}h{EBCDIC}e{ascii}' with 'T{EBCDIC}h{ascii}e{EBCDIC}'--do they match or not?


      Examine what is said, not who speaks.

        I've studiously avoided the term "flyweight objects" as I have only ever seen it here and didn't really understand its meaning. I'll stick to "Inside-out" which only has meaning in perl terms as far as I am aware.

        Fair enough, but other people have - which makes me suspect it means something different in the perl and design pattern worlds.

        Which would be annoying. One of the main advantages of the design pattern movement for me is the development of a common vocabularly (finally, everybody knows what a singleton is :-). If it means something different in the perl world it would be useful to know.

        With regard to the example you describe, that may have made some sense in the world of 8-bit chars as you only need a pool of 256 object, but in the world of UCS, it becomes excessive I think...

        I don't really want to repeat everything in the chapter from the book, but basically...

        • The context is a word processor, so "character" doesn't just mean the code, it might support methods like draw(), intersects(), etc. We're talking WYSIWYG layout support.
        • I didn't mean to imply you had to create the whole pool of characters at once, you would create them as needed for a document and add them to the pool.

        As for practicality, the example was in the book was adapted from the Doc editor, produced using InterViews 3.0. Take a look at:

        • Paul R. Calder and Mark A Linton. Glyphs: Flyweight bjects for user interfaces. In ACM User Interface Software Technologies Conference, pages 92-101, Snowbird, UT, October 1990.
        • Paul R. Calder and Mark A Linton. The object-oriented implementation of a document editor. In Object-Oriented Programming Systems, Languages and Applications Conference Proceedings, pages 154-165m Vancouver, British Columbia, Canada, October 1992. ACM Press.

        To quote from the Design Patterns chapter on flyweights:

        Doc uses glyph objects to represent each character in the document. The editor builds one Glyph instance for each character in a particular style (which defines its graphical attributes); hence a character's intrinsic state consists of the character code and its style information (an index into a style table). This means only position is extrinsic making Doc fast.

        If you're interested in the details I'd recommend picking up a copy of Design Patterns and giving the flyweight chapter a read.

Re^3: Yet Another Perl Object Model (Inside Out Objects)
by adrianh (Chancellor) on Dec 15, 2002 at 14:56 UTC
    As for the bug that you guys encountered, one thing that can be helpful is to prevent modules from being updated by using file security. That way unexpected changes arent introduced into a running system. I agree with you that this type of error is unusual however.

    Oh yes. I had a long, and somewhat painful, chat about the source control system after that incident :-)

    I agree that the version mixup shouldn't have happened, but it wouldn't have been a problem if we'd used inside out objects.

    (and I just want to say again that kind of problem is very rare in my experience)