in reply to Re: Help with ADT
in thread Help with ADT

Yes, it does. If you're within an object and you're doing 2- and 3-deep lookups into $self, you're programming horribly. It's mean, but true.

Even within an object, you should be using your accessors. In addition, using objects would allow you to abstract out some of the parts of this ADT. For example, dimmesdale has this concept of a "measurement". That should be abstracted out to some other object. Now, you deal with anything in that measurement through that API. This actually solves his initial problem.

Plus, I suspect that he's working with test subject data, from the little he posted. There are usually hundreds of measurements for a given test subject. So, he has a List of Measurements within a TestSubject, all with appropriate accessors. The DB-access methods are now a piece of cake. The display methods are a piece of cake.

I'm not always "OO rulez" or whatever. But, if the shoe fits ...

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Replies are listed 'Best First'.
Re: Help with ADT
by Abigail-II (Bishop) on Jul 25, 2002 at 15:30 UTC
    If you're within an object and you're doing 2- and 3-deep lookups into $self, you're programming horribly. It's mean, but true.
    First of all, in the given example, we are not using objects. But that's not really relevant. However, if you consider 2 level deep lookups to be "horrible", then there's an awful lot of horrible code out there. Sometimes a 2 or 3 level deep lookup could be coded better. But dismissing any 2 or 3 level deep lookup as "horrible programming" is just stupid. That would mean you couldn't even access an entry in a two dimensional array without an intervening method lookup.
    $self -> {$feeble} {$fubble};
    isn't in anyway harder to understand than
    $self -> feeble ($feeble) -> fubble ($fubble);
    Except that the latter exposes the method feeble to the outside world and is less efficient.

    Of course, non of your advise would have brought him a micron close to solving his problem. You still can't treat a reference to an array as a reference to a hash, or the other way around, regardless how deep you do your lookups.

    Abigail

      I'm not advocating that all 2- and 3-level deep lookups are bad. If they're within an object, you should be considering to have a has-a relationship going on, abstracting out that complexity. In my eyes, you need to prove that a 3-deep lookup is necessary, within an object. Usually, you're better off abstracting it out.

      If the abstraction takes place, he'll find the reason(s) why he's trying to do what he's doing. It's a design issue, made difficult because he's dealing with too many pieces of information at once.

      ------
      We are the carpenters and bricklayers of the Information Age.

      Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

        I will prove that 3-level deep lookups are necessary, as soon as you can prove that objects are necessary.

        In the mean while, I'll make a patch to remove all looping constructs from Perl. In more than a dozen years, noone has proved those are necessary. (We do have goto after all).

        Requiring a necessity proof is just really, really stupid, unless you want to code a minimal language.

        Abigail