![]() |
|
Don't ask to ask, just ask | |
PerlMonks |
A tale about accessors, lvalues and tiesby LanX (Saint) |
on Nov 18, 2008 at 13:32 UTC ( [id://724256]=perlquestion: print w/replies, xml ) | Need Help?? |
LanX has asked for the wisdom of the Perl Monks concerning the following question:
Hi
In OOP it really bothers me to As shown in PBP, the problem with lvalue is, that if ever you need a wrapper to control the setting of the attribute you can only rely on tieing the variable or you have to change the API and refactor... Which is not really an issue of ugly syntax, I found at least two cpan-modules showing that a posteriori FETCH and STORE can be done in a very clean, readable and maintainable syntax. e.g. in Class::Closure I did some benchmarks showing that accessing a tied variable via lvalue is 4-5 times slower than with a getter sub! : ( Now I "superfound" Re^3: Class::Accessor and Damian's PBP and was quite exited to see Contextual::Return... So, very curious about how TheDamian fixed the problem, I took a look into the source:
Do I get it right, it's just another sugar for Tieing? 8 ( Well I don't know how big the trade-off of wrapping lvalues is in other languages ... But shouldn't this general "banning" of lvalues better be replaced by the rule It's acceptable to use them as long you are aware that later changing will result in a call-overhead of 400%! ??? BTW: Is there any activity to speed up tie? I don't see why the calling mechanism for FETCH and STORE needs to undergo the same slow dynamic ways OOP needs. A kind of "tie :static" might really solve the problem! Hopefully looking for a serious discussion of this somehow "religious" matter.. Cheers LanX - - - - - Which song???
Back to
Seekers of Perl Wisdom
|
|