Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^4: Use method/function signatures with Perl

by tilly (Archbishop)
on Dec 07, 2004 at 16:49 UTC ( #412940=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Use method/function signatures with Perl
in thread Use method/function signatures with Perl

Funny. I thought that I just said that Attribute::Property is an unacceptable solution to me. That means that it doesn't take away the issue.

But you're right that validation is not the only thing that I object to about lvalue accessors. With OO I'd expect to be able to do something like create a Length module, Length objects can be accessed/set in various units (inches, meters, feet, miles, etc). An external user should have no idea what the internal representation is.

How do I do it with lvalues?

I guess that you can use tie, but implementing that takes enough work and adds enough surprise that I don't see it as a net win.

To me the syntactic sugar is simply not worth the extra work and complexity.

As for Perl 6, I'll evaluate each feature and come up with my own opinions. I'll feel free to ignore anything that I don't like - the language is rich enough that I have no shortage of viable choices for which subset of features to use and which to ignore. If I don't like the implementation of lvalue subroutines there, I'll ignore it like I what Perl 5 does. If I like it, then I'll feel free to use it like I would in Ruby.

And whichever I do, I'll feel free to dislike people who categorically declare that my considered set of choices are flawed.


Comment on Re^4: Use method/function signatures with Perl
Re^5: Use method/function signatures with Perl
by Juerd (Abbot) on Dec 07, 2004 at 18:53 UTC

    Funny. I thought that I just said that Attribute::Property is an unacceptable solution to me. That means that it doesn't take away the issue.

    I'm not disagreeing about that. You said that I indicated something; I cannot recall having indicated that exact thing, and tried to correct.

    Let's not make a big deal out of everything. Feel offended if you wish, but please only do so knowing that I didn't mean "flawed" as an absolute condemnation and that no offense was intended. I like Perl for its tolerance towards almost all programming styles, but that doesn't mean I steer clear of discussion.

    With OO I'd expect to be able to do something like create a Length module, Length objects can be accessed/set in various units (inches, meters, feet, miles, etc). An external user should have no idea what the internal representation is. How do I do it with lvalues?

    In that rather specific case I would not use lvalues, or any setter method, for that matter. I'd be inclined to think of these values as immutable objects, and have something like:

    package Length; sub new { my ($class, $value, $unit) = @_; # Create $self and store the value in standard form. # In case of length this means converting the length to meters. } sub as_km { shift->{_m} / 1000 } sub as_hm { shift->{_m} / 100 } sub as_dam { shift->{_m} / 10 } sub as_m { shift->{_m} } sub as_dm { shift->{_m} * 10 } sub as_cm { shift->{_m} * 100 } sub as_mm { shift->{_m} * 1000 } # Or, if this were really something I made, just: sub as { my ($self, $unit) = @_; # ... }
    But instead of using Length objects, I am much more likely to dictate that every length must be stored in meters, as a number. Possibly with the addition of utility functions to aid in conversion.

    And whichever I do, I'll feel free to dislike people who categorically declare that my considered set of choices are flawed.

    I'm sorry you make this about people. I wonder, though, how you survive PM if you take offense every time someone disagrees with you on a technical subject. You are of course free to dislike me, or any person. Even though we will probably never meet in person, I regret that you dislike *me* instead of only what I said.

    Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2014-07-24 02:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (156 votes), past polls