Beefy Boxes and Bandwidth Generously Provided by pair Networks httptech
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Re: Re: Why get() and set() accessor methods are evil

by pg (Canon)
on Nov 25, 2003 at 13:07 UTC ( [id://309989]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Re: Re: Why get() and set() accessor methods are evil
in thread Why get() and set() accessor methods are evil

You are right, as Java also has primitive types.

But on the other hand, in this case, I can choose to return, for example, an ArrayList of Integer. This is much less a problem to languages that have stronger OO support.

Update:

Thanks BUU for the extension, tie was actually something I thought of. The idea of tie, actually holds some characteristics that OO interface provides.

  • Comment on Re: Re: Re: Why get() and set() accessor methods are evil

Replies are listed 'Best First'.
Re: Re: Re: Re: Why get() and set() accessor methods are evil
by BUU (Prior) on Nov 25, 2003 at 13:43 UTC
    So why couldn't/wouldn't you do the exact same in perl? You could even do it transparently via tie, or you could do it overtly by creating the object. Seems fairly simple to me at least.
    package ArrayList; my $i; sub new{shift;return bless{[@_]=>shift};} sub iterate{return $_[0]->[$i++]}
    And so on and so forth.

      One reason you wouldn't want to is that is Perl's context-sensitivity. By using ArrayList, which would be implemented as a scalar holding a referance, you're now putting things in scalar context that really should be in list context.

      BTW--Check out the Class::Iterator module for doing this.

      ----
      I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
      -- Schemer

      : () { :|:& };:

      Note: All code is untested, unless otherwise stated

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://309989]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.