Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^9: Experimenting with Lvalue Subs

by dragonchild (Archbishop)
on Jan 25, 2005 at 15:09 UTC ( #424889=note: print w/ replies, xml ) Need Help??


in reply to Re^8: Experimenting with Lvalue Subs
in thread Experimenting with Lvalue Subs

It seems to me that your expectations are completely in line with current :lvalue subs, do you find them useful?

My reply, from the post you're replying to, would be:

Then again, the entire lvalue thing is ... it's just plain stupid, in my opinion.

I don't know of any benefit to having lvaluable subs that either

  • doesn't break OO encapsulation
  • obfuscate the intent of the programmer

Of course, and as always, I would be delighted to be proven wrong.

Being right, does not endow the right to be rude; politeness costs nothing.
Being unknowing, is not the same as being stupid.
Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.


Comment on Re^9: Experimenting with Lvalue Subs
Re^10: Experimenting with Lvalue Subs
by demerphq (Chancellor) on Jan 25, 2005 at 15:23 UTC

    My whole point here is that the term "lvalue subroutine" has been taken to mean "the same thing as VB/Java properties." But its not. Larry is solving a different problem to that which we care about: simple syntactic sugar so we can write things like

    $obj->hashlikeproperty($key)=$value; $obj->scalarlikeproperty=$foo; $obj->flexibleproperty=(1..10); $obj->flexibleproperty=5;

    and have them be some sensible equivelent method call. Id say that few of us care if we can use such a sub as a slot in a list assignment, or if we can take a ref to the "value" the property represents or if we can localize it (how the hell you localize a change that may have massive sideffects is beyond me). We dont care about weird stuff like that much, we dont even care much if $o->prop++ gets translated to two method calls. (If we were really concerned about such things we probably wouldnt be using Perl at all.)

    We want the side effects, we want validation, it would be nice if we could handle list and scalar assignment in a single sub, but bottom line we just want the syntactic sugar and we really dont want to have to create ties for it every time. In fact it seems to me that ties arent even appropriate as there isnt any efficient way via a tied interface to do things like set a full array in a single go, instead it gets translated into zillions of STORE calls. Hmm, actually thinkign about it further i can imagine cases where a tied approach flat out wont work at all. How do you do something like

    $obj->average=(1..10); #assign 5.5 as the average $obj->average=2.5; #assign 2.5 as the average

    With a tied/lvalue interface?

    ---
    demerphq

Re^10: Experimenting with Lvalue Subs
by BrowserUk (Pope) on Jan 25, 2005 at 15:35 UTC

    First off, you are assuming that an lvalue sub has to expose an actual attribute of the object.

    Which is understandable as with the current P5 implementation and the proposed P6 implementation, where you cannot do anything after the assignment takes place--you are right.

    But now imagine that the method was passed the rvalue when the method was invoked. Now you can do anything with it, like validate it, but also use it to derive some other value or a whole collection of values that then are then assigned to attributes of your object--none of which happen to have the same name as the method invoked.

    The desirable feature is not the direct access to the underlying entity, it is the syntax that allows:

    $obj->thing++;

    in preference to

    $obj->set_thing( $obj->get_thing() + 1 );

    Whether thing is actually a piece of ram within the object or a conceptual attribute of it is secondary.

    Equally, whether that example has to "call the function twice", once to get the value and once to modify it, is an implementation detail that should be transparent.


    Examine what is said, not who speaks.
    Silence betokens consent.
    Love the truth but pardon error.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://424889]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (12)
As of 2014-07-24 11:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (160 votes), past polls