in reply to Re: Re: Why ref() is bad.
in thread Is "ref $date eq 'ARRAY'" wrong?

To be honest, I am not yet sure what the best answer is. In general, I've stayed out of discussions regarding how best to use OO in perl (5) simply because I haven't seen a truely complete approach to putting OO together with perls dwimery such that you don't end up with dilemmas like this.

This sort of leads to the same set of thoughts that I had in my mind when I wrote this earlier today.

I've played with various OO techniques and modules from CPAN, but I invariably run up against some barrier, limitation, logical or syntactic inconsistancy that prevents me from getting the interfaces to work quite the way I would like them to.

So far, my attempts at trying to put together a clean and consistant implementation of classes that utilise all of these techniques in the same class have always ended up with an inconsistancy, or requiring undesirable copy&paste coding somewhere down the line.

Even simple things like inside-out objects leave me undecided. If your class has 3 physical attributes, do you code that as

package MyClass; my %instances; sub new{ my( $class, $attr1, $attr2, attr3 ) = @_; my $self = bless {}, $class; return $instances{ $self } = [$attr1, $attr2, $attr3]; }

or

package MyClass; my( %attr1, %attr2, %attr3 ); sub new{ my( $class, $attr1, $attr2, attr3 ) = @_; my $self = bless {}, $class; $attr1{ $self } = $attr1; $attr2{ $self } = $attr2; $attr3{ $self } = $attr3; return $self; }

The former is shorter and less profligate with space. The latter results in less complex syntax when referencing the attributes with the methods, but relies upon "parallel arrays", which I normally consider a bad idea. It also consumes more memory.

The complicated syntax of the former can be diffused by using (private) accessors/mutator functions, but that adds to the performance overhead.

If the objects are largish and few in number and not called in tight loops, neither is too much of a problem, but if the objects themselves are pretty small, but you need to use lots of them and/or call their methods in tight loops, then the overhead in memory and performance is a pain.

Maybe the answer is to wait until P6 for a clean solution and just muddle through for now?