Hi

In OOP it really bothers me to write use getter/setters instead of lvalues for simple attributes like in other languages.

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:

$impl = tie $_[0], 'Contextual::Return::Lvalue', $subname => $handler, args=>$args;

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%!

Time critical calls should be done with getter/setters!

???

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???

UPDATE: fixed some typos, some English, some mark up ...

In reply to A tale about accessors, lvalues and ties by LanX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.