Sammy Larbi
10/26/2006 1:01:00 PM
Pa Per wrote:
> I've been thinking about using a relational approch using two [storage
> units], one containing type and positional data of a line, while the
> other just stores line-type related information as color, width, ..
>
> As arrays apparently only support integer keys, and the order in which
> the line elements are stored does not really matter, my guess is that a
> hash using the position of each line (float) as keys, and the style of
> line as value, plus another hash or array that contains just the
> different styles might be a good approach.
>
> Then I could iterate with the step method to insert an element, if there
> is none yet. Resulting in a 'list' with all lines.
> I assume that I then could easily extract a specific type of line, fetch
> the corresponding style information from the other list, and voilà ! -
> generate what I want.
>
> Could you kindly provide me with your thoughts about this approach? If
> it is not doomed, I shall gain motivation and so will be able to try out
> procedural and OO constellations, learning the wonderous workings of
> arrays and hashes, and eventually improving the program, so everyone
> will be able to create her/his badly-needed ruler..
>
> I have access to books describing OO with UML, but maybe I can extract
> the concept without having to 'bother' about UML yet.
>
>
I like to stick with the metaphor as much as possible, as it makes it
easier when you come back to it after several months or years, or
someone else works on your code, to figure out what was going on.
In that vein, one question I have about your proposed storage mechanism
is: How will you know where the lines belong? I mean, if you store it
based on a hash where the key is the position, how will you remember the
position? Sure, you can get all the keys, but it seems like an extra
step that is not needed. It seems to me that a position is an attribute
of a line, and that information would be better suited there. As you
mention, the order doesn't matter. But, that doesn't mean a hash would
be better than an array, simply because it doesn't take order into
account. If an array works and order doesn't matter, don't sort it. =)
It sounds like you are making it harder than it needs to be (though, it
still is simple, I just think arrays are "simpler" than hashes).