> Just finished a marathon coding session and thought I'd share/get some
> opinions on some of the things I've found concerning CFCs and sorting.
> I'm new CFCs and OO, so much of this may seem amateurish, but I expect
> that many CFers are in the same position.��I hope it may help somebody
> or prompt discussion that heads off bad habits before they set in.
>
You may find better responses if you send each of your questions
separately as this email is rather long and touches on several subjects.

> I began, as everything I've read suggests, by creating an internal
> array
> to hold the components.��I now think that was a mistake and have
> switched to structures to maintain the internal data.��However
> structures can't maintain an explicit order, something Arrays do by
> design.
>
It can often be hard to choose between arrays and structures since
sometimes you want properties of each one. Thus, it is often necessary
to create a data structure that has the properties you want instead
working around a problem in an available data structure.

> Sorting arrays of components is a pain.��ArraySort() won't work on
> arrays of complex objects so you're left with doing some sort of bubble
> sort, going back out to the database, or using some sort of proxy
> (creating, for example, a query using Query of Queries).��All of these
> are inelegant solutions in my opinion.
>
Implementing a well known sorting algorithm shouldn't be that difficult
since all the popular ones are well documented and have examples
available in many different programming languages. Bubble sort is
generally not a very good one. Generally speaking, quick sort is
usually the best choice.

> As always I'd love to hear opinions on this from those that know more
> than I do (which includes... well, pretty much everybody).��Are there
> actually good reasons to use arrays rather than structs?
>
IMHO, since all you want is to maintain key/value pairs in order, what
you need is a Map that keeps its entries in order. The JDK provides two
classes that do this, LinkedHashMap and TreeMap. Additionally, Apache
Jakarta Commons has a number of other Map implementations that keep
their entries in order. If you'd like an example of using one of these
classes let me know.

Of course, you may want nothing to do with Java and would rather handle
the problem in CFML. If so, I would suggest creating your own ordered
Map as a CFC. To do that you would create both an array and a structure
to hold your data. The CFC would manage keeping the two in sync, which
shouldn't be hard considering one would likely only hold references to
the other. Then whenever you need to access your data as an array you
have an array to access it with. When you need to access your data as a
structure then you also have a structure to access it with.

Matt Liotta
President & CEO
Montara Software, Inc.
http://www.MontaraSoftware.com
(888) 408-0900 x901

[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to