Discussion: Collections in Actionscript 3?

I’ve seen a few collection frameworks in Actionscript, but you never really here of any of them being used as a standard. That kind of acceptance is hard anyway, but I’m really surprised that it hasn’t happened in the community. I think for the longest time the argument was simply that having that kind of extra weight was unjustified, and was strengthened by the fact that Arrays quite simply are much faster. But those are forgotten times, aren’t they? I mean with everyone on the OOP kick. I don’t know, I wanted to put some stuff together just to see how useful a collection framework would be, and how much of a performance hit I would take by using one.

Rather then adopt one I decided to take a stab at implementing it (silly me), after all it’s just for experimenting right now. I’m opening this thread as a discussion about what I plan on doing, and what I am thinking. I will work on it gradually, each time I change a major component, or release a new component altogether it will be in its own post.

Now unfortunately, I’m just not that smart :-\, sorry. So I’ve spent some time looking into it, and picked up some books. I wanted to make a note of one of them though, because it has proven to be incredibly helpful. It’s “Data Structures and Algorithms with Object-Oriented Design Patterns in Java by Bruno R. Preiss”. Check it out. If you’ve read it you would notice that it is an obvious source of the inspiration for my code. The thing to remember is that Java and Actionscript, while similar in syntax, are two very different languages, so my code will differ where things can be done in a way that is more appropriate for Actionscript.

For simplicity and the sake of performance I am going to stick with using Array and Dictionary objects for the implementations of the different data structures.

My initial effort is to get the following done relatively soon.

  • Collection
  • AbstractCollection
  • Stack
  • Queue
  • Tree
  • BinaryTree

There is a lot more to be done then that, but I think its a fair list to commit to for now. Of course any of these could probably be put together quickly if need be, however I want to focus on making a useful framework of collections, something reliable.

I decided to set up a google code project for it, who knows, may just be wasting time.

project:
http://code.google.com/p/as3-collections/

svn:
http://as3-collections.googlecode.com/svn/trunk/

So, if you don’t here from me for a few days, you know why :) Although I’m going to try and get at least the basic containers out tonight, or tomorrow morning.

4 Responses to “Discussion: Collections in Actionscript 3?”

  1. eric Says:

    Have you seen Polygonal Labs “AS3 Data Structures For Game Developers” ?
    http://lab.polygonal.de/ds/

  2. Michael Avila Says:

    Eric-

    Yes I have, Drew and I were talking about them not too long ago. These look solid, and I still have plans to play around with them a lot more.

    I will still be finishing mine since I had a goal, and a specific approach. Thanks for pointing it out! I was planning on including a reference to it in one of my overview posts, as it is a recent discovery for me… ;)

    Thanks again!

  3. Denis Says:

    Michael,
    I am equally amazed that decent solid collection libraries are not the norm. There also seam to be no stream libraries either. While I am an ActionScript newbie, I am am a 15 year Smalltalk vetaran and this sort of stuff is just standard kit. Just to give an idea of standard colleciton classes:

    Collections-Abstract
    Collection
    ArrayedCollection
    SequenceableCollection
    KeyedCollection

    Collections-Arrayed
    RunArray
    Array
    ByteArray
    LargeWordArray
    WeakArray
    WordArray
    DwordArray
    LargeArray
    IntegerArray
    SegmentedCollection

    Collections-Sequenceable
    OrderedCollection
    Interval
    SortedCollectionWithPolicy
    LinkedList
    SortedCollection

    Collections-Unordered
    Bag
    OrderedSet
    EphemeronDictionary
    Dictionary
    WeakDictionary
    Set
    IdentityDictionary
    IdentitySet

    May I humbly suggest, don’t take your lead from the Java world where they are still getting their head around real OO and instead take your lead from the dynamic language crowd. In particular I would love to see someone do a collection library which does not use iterators and does them using closures/blocks like Smalltalk.

    Good luck with your library and feel free to discuss via (allobjects at optusnet dot com dot au)

    cheers Denis

  4. Michael Avila Says:

    Denis - Thank you. I am looking into everything you mentioned. I will definitely take all of this into consideration, that is the beauty of still being early on in development :-) .

Leave a Reply