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

What prevents you from writing, say, a Tie::IntRange class that constrains the values assigned to the scalar it ties, and reusing that code 1,500× for all your 1,500 attributes (with a different range declared in each instantiation of the tied class)? Or Tie::EnsureMatch which constrains the values assigned to the scalar it ties to those matching a particular regex supplied at instantiation time?

This kind of reuse is really no different from what we already use Params::Validate for in another context.

Makeshifts last the longest.

Replies are listed 'Best First'.
Re^8: Experimenting with Lvalue Subs
by TimToady (Parson) on Jan 25, 2005 at 19:30 UTC
    You're on the right track. Attaching validation routines as setters is falling into a kind of cut-and-paste fallacy. Most such validation should really be done by the subtype system in Perl 6. Merely declaring your attribute to be of the proper subtype will prevent bad values from being assigned to it. The subtype is usually the proper place to attach your validation sub, not the attribute setter.

    Anyway, I'm kind of sick of this thread. People are getting exactly the same kind of tunnel vision they had when they wrote the RFCs in the first place, and not seeing how the Perl 6 feature set works together as a whole. They don't see how syntax mutability and dispatch rules will let them cargo cult in whatever silly syntax they like; they'd rather screw around with the clean underlying semantics instead.

    Gee, let's just recapitulate the whole RFC process here on PM. Maybe it's about time to trot out highlander variables again. Multiline comments anyone? Ooh, let's make my the implicit default. And I've got this great idea for the colon character... :-)

Re^8: Experimenting with Lvalue Subs
by BrowserUk (Patriarch) on Jan 25, 2005 at 10:56 UTC