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

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

Replies are listed 'Best First'.
Re: Re: Help with ADT
by dragonchild (Archbishop) on Jul 25, 2002 at 15:41 UTC
    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

        I'm not taking the position that it's a necessity or non-necessity. I'm saying that, as a rule of thumb, using objects where they make sense will make your life easier. For me, whenever I see ADT's, I automatically think of using objects and I would need reasons why they aren't necessary. I'm not saying that EVERY ADT should be an object. Far from it! But, I would say that the case is not whether to use objects, but whether not to use objects.

        As for n-deep lookups - whenever I see a lookup that's 2 or 3 deep, especially when mixing hashes and arrays, that is a signal to me that something can be abstracted out. It's the same case, actually. I automatically think of abstracting something out and would need reasons not to. I don't pendantically abstract everything out. I just feel that there would need to be a reason not to abstract vs. a reason to abstract.

        Plus, I"m a little confused as to the tone you're taking with this whole dialogue. I may have been a little curt and know-it-all initially, but I apologized for that and have been attempting to clarify my initial position. I feel, and this is not meant to be a flame, that you have been deliberately obtuse towards me. Now, I appreciate the sustained and very direct questioning you've given me, as it's forced me to clarify for myself my position(s) on this matter. But, I feel I have made a number of good points regarding rules of thumb derived over years of experience. Yet, you haven't acknowledged them at all. Is there something I'm missing that you haven't made clear to me that would let me know where I'm stepping wrong with you?

        ------
        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.

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

        Don't forget recursion :)

        Speaking of that, do you happen to know if perl does a tail-end recursion method kind of like Scheme (which interestingly enough doesn't have looping constructs :)