We don't bite newbies here... much | |
PerlMonks |
Re: Tied Variables - why?by Arien (Pilgrim) |
on Sep 07, 2002 at 11:34 UTC ( [id://195863]=note: print w/replies, xml ) | Need Help?? |
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):
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
In Section
Meditations
|
|