in reply to Nested data structures... nasty?

It's a myth that Perl has more complex datastructures than other languages. It doesn't. In fact, Perl doesn't even have complex datastructures build in the language. All it has are scalars, arrays, hashes, and references. That's it.

It's a mistake to consider $foo [$bar] {$baz {$quux}} to be a complex datastructure. It ain't. It's still arrays and hashes. One does the same thing in C, except that one is more likely to use a struct instead of a hash. But in C, that still isn't complex. Now, a five dimensional partition tree using epsilon nets, with associated k-d trees in the nodes, that's a complex datastructure.

The only thing "complex" about $foo [$bar] {$baz {$quux}} is the long single expression to get an element out of it. But you have your data, and you need to store you data somewhere. Preferably in a way to retrieve your elements. And regardless whether you use arrays, hashes, or objects, you have two options. Either you nest, or you don't. And if you nest, you either use long single expressions to get to the data, or many short expressions. (Note that this is independent of the language you are working in). If you don't nest, I doubt your datastructure becomes any clearer.

BTW, I don't agree with Rob Pikes claim which FoxtrotUniform brings up. Nor do I agree with Wirth's "Algoritms + Datastructures = Programs". I believe that datastructures imply the algorithms. One cannot choice a datastructure and afterwards come up with the algorithm. The algorithm has to follow the rigids of the datastructure.

Abigail

Replies are listed 'Best First'.
Re: Re: Nested data structures... nasty?
by hsmyers (Canon) on May 29, 2002 at 02:17 UTC
    You said:
    Now, a five dimensional partition tree using epsilon nets, with associated k-d trees in the nodes, that's a complex datastructure.
    Seems arbitrary to me. How about 4 dimensional? Or 3 dimensional using red-black trees? Or AVL trees? Where in particular do you draw the line in the data structure sand that says complex on this side, everything else on that side? I'm not saying that complex data structures don't exist, I'm just wondering about how you distinguish complex from not complex...

    –hsm

    "Never try to teach a pig to sing…it wastes your time and it annoys the pig."
      I'm just wondering about how you distinguish complex from not complex.

      Well, I don't think it's possible to draw a sharp border. Just as it's almost impossible to draw the line when you call it "light" or "dark". That doesn't mean that in a lot of cases, it's clear when it's "light" or "dark". ;-)

      Anyway, for me, to call a datastructure complex it usually satisfies these points:

      • It stores elements where the place in the structure implies (or is implied by) a (spacial) relationship between the elements.
      • It's optimized such that queries and/or updates can be done in less time than a full scan, or a rebuild of the entire datastructure.
      • It will often have some kind of associated datastructure.
      But I don't apply the rules very strict.

      Abigail