in reply to Re: Re: multi-tier collections & lack of modulization/OO
in thread multi-tier collections & lack of modulization/OO

Of course there is always more than one way to do things. If I were to implement an array of which I always mantained a statistical average of the values of its elements, I might consider tieing the array to a module that overloads the STORE function (and all other applicable to the situation) so that any time a new value is added by any means, the statistical average attribute is updated.

The attributes could then be obtained via access to the object's methods. ...perhaps a "getstat()" method which would return a reference to a hash of stats.

Such an approach would guarantee that the stats are always accurate, as there would be essentially no way to modify the array without the stats being recalculated. Performance would suffer a bit, but accuracy would be guaranteed. By using a tied array, the user could do whatever the hell he wants, directly to the array, and an accurate stat. would still be maintained.

:) Just a thought. And of course, it came to me because I've been playing with tied variables the past few days. Seems like a cool solution though.


Dave

  • Comment on Re: Re: Re: multi-tier collections & lack of modulization/OO

Replies are listed 'Best First'.
Re: Re: Re: Re: multi-tier collections & lack of modulization/OO
by BUU (Prior) on Dec 12, 2003 at 06:43 UTC
    You realize that you aren't actually changing anything? All you are doing is making the method calls implicit rather then explicit.
      Yes, I realize that.

      The example given was using object methods as an interface to an object that encapsulated an array with a statistical attribute.

      My point was that, for the programmer using this module, it might be more familiar ground for the object to look and feel (from the outside) just like a plain old array. In my example, there isn't a new API to learn. And code using the object will look and feel pretty basic. A Perl programmer plays with arrays all the time. We're all pretty much used to the "interface" to arrays. In this case, the simple (for the programmer utilizing the module) approach is to carry that idiom forward seemlessly, or transparently for simplicity's sake. The only thing to learn would be what object method to use in accessing the array's statistical attribute.

      Yes, nothing has really changed internally. But externally, the module's user only has to remember how to play with an array.

      But this is all a big tangent on the OP's thread. I have to agree with the OP that the complexities of a datastructure are often better dealt with through layers of objects. However, I don't entirely agree. The objects should be used to simplify life, not to make it more intricate. Occasionally a complex data structure provides simplification rather than undue difficulty. It's not always bad to let the cat out of the bag.


      Dave