in reply to A tale about accessors, lvalues and ties

Direct attribute access is a pretty old OO discussion. You're welcome to look up the old arguments about accessors and whether they should always be used, but I can't see anyone coming up with anything new at this point. You just have to make your choice.
  • Comment on Re: A tale about accessors, lvalues and ties

Replies are listed 'Best First'.
Re^2: A tale about accessors, lvalues and ties
by LanX (Saint) on Nov 18, 2008 at 19:43 UTC
      Ok, your reference to needing a wrapper to control the setting of the attribute made me think you were talking about direct access. I'm definitely not a fan of lvalue subs or tie. Other than Ruby, are there any languages that support syntax like "object->method = value"?
        Perl 6 ! ; )
        my sub thingie is rw { return my $var is Proxy( for => $hidden_var, FETCH => { ... }, STORE => { ... }, TEMP => { ... }, ... ); }
        see Apocalypse 6

        But I'm not sure if it is really faster than what we already have in modules like Contextual::Return.

        Depends on how fast ties are realised in p6...

        Cheers LanX
        > Other than Ruby, are there any languages that support syntax like "object->method = value"?

        Python does via so called properties. But I don't know any implementation or performance details.

        This way simple attributes can be easily turned into mutators without any need to change the API.

        > I'm definitely not a fan of lvalue subs or tie.

        OK, it seems overcomplicated to do it this way. But IMHO it's stable, has no side-effects and can be hidden behind a nice syntax. It's just slow!

        Look, I don't know every archive discussion, so I'm relying on PBP. ... But the reasoning "Don't use lvalue-attributes because you will be forced to use tie afterwards and we showed you earlier that tie is evil" is shallow.

        All "earlier arguments" against tie in PBP do not apply with lvalues, except the slowness!

        So tuning up tie would solve the whole thing. I mean an alternativ static version hooking wrapper-method directly to variables.

        Or does anyone have a good example, where tie profited from resolving methods dynamically and having inheritance and overload and the other OO stuff?

        Cheers LanX

        .NET


        holli, /regexed monk/