in reply to Tied Variables - why?
I think tied hashes add an unnecessary layer of complexity that doesn't make much sense when you already have objects. ... You formally declare your behavior instead of hiding it behind the way that perl NORMALLY behaves.
What behaviour is there to hide when it's the usual behaviour you've come to expect of Perl?
The key to tied variables is to make them look so much like a regular variable that you forget what is going on underneath. Obviously, you can only get this to work if the behaviour you're trying to implement maps nicely on the normal behaviour of whatever your tieing to.
Your example shows what happens when there is a impedance mismatch between the behaviour you're implementing and how the variable type you've chosen for your tie normally works in those circumstances. The conflict with the expected behaviour is a result of using the wrong metaphor: you are luring the user into thinking all is normal, when in fact it is not.
As an example of a module, have a look at Tie::File, which does this (example code snipped):
Tie::File - Access the lines of a disk file via a Perl array.
Tie::File represents a regular text file as a Perl array. Each element in the array corresponds to a record in the file. The first line of the file is element 0 of the array; the second line is element 1, and so on.
The file is not loaded into memory, so this will work even for gigantic files.
Changes to the array are reflected in the file immediately.
Lazy people and beginners may now stop reading the manual.
Because you know how arrays work, you could now very likely start using this module without any problem whatsoever. If you had to use a "similarly coded class" you would still be going over the methods to see how things work in this particular case.
Now, that is the beauty of using tie.
— Arien
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Tied Variables - why?
by Anonymous Monk on Sep 07, 2002 at 17:18 UTC | |
by Arien (Pilgrim) on Sep 07, 2002 at 21:01 UTC | |
by Anonymous Monk on Sep 07, 2002 at 23:13 UTC | |
by sauoq (Abbot) on Sep 07, 2002 at 23:43 UTC |