New data structures library released

I’ve just released the first official version of ‘ds‘ (aka data structures), the successor of as3ds which is written in the HaXe language. (The name hx3ds was used during development and is obsolete because ds is now a module of the polygonal library).

The library is found here: http://code.google.com/p/polygonal/. There is also wiki page describing how to use it with ActionScript 3.0 (there are still some issues with the HaXe generated SWC files, I hope Nicolas finds some time to address them in a future release).

What’s new

The new release (changelog) contains many bug fixes, new features and a refined documentation. While there are still many things on my TODO list, I think the library is stable enough so it deserves to be the first major release. And since I’m using the library in all of my projects, you can expect some regular updates.

Why the heck HaXe !?

Firstly, ActionScript 3.0 doesn’t support any kind of generics/templates like Java does for example. The typed vectors introduced in FP10 are too crippled and limited so in the end you are still stuck with dynamic containers, which is a bad for complex projects. HaXe supports type parameters – in the image below you see that I’ve created a graph of stacks of hash maps and everything is typed. The nice thing is that you still get auto-completion:

FlashDevelop HaXe AutoCompletion

Secondly, HaXe provides a lot of syntax sugar that sweetens your daily coding experience. As an example, consider iterating over a collection. In HaXe it’s just:

//iterate over all elements of a 2D array:
var a = new Array2<Int>(3, 3);
for (i in a) trace(i);

In AS3 you have to create an iterator object and explicitly call the next() and hasNext() methods:

var a:Array2 = new Array2(3, 3);
var itr:Object = a.iterator();
while (itr.hasNext())
{
  var element:* = itr.next();
  trace(element);
}

In general, HaXe implicitly does a lot of things for you! Probably one of the best language feature is type inference/implicit typing, which is absolutely brilliant for quick prototyping. It’s like writing AS1 but without compromising speed and type safety. At first it’s hard to get used to it because all ActionScript text books never get tired of repeating how important typing is and that everything should be typed. But If you think about it, the compiler should handle it where possible and relieve the developer from writing clumsy types over and over again:

//AS3
var n:Number = 1;
var i:int = 1;

//HaXe
var f = 1.0; //compiler infers that n is a float
var i = 1; //compiler infers that n is an int

Thirdly, because as3ds was all about efficiency I couldn’t resist HaXe because it’s much faster. From my experience, ds performs ~2-6x better than as3ds. Same runtime, huge difference!

11 Comments

  1. This looks great! One question: If I use it in a ActionScript project, compiled with mxmlc, does it still take advantage of the fast ‘alchemy’; ByteArray ?

  2. This looks really delicious! is FlashDevelop still the only editor choice for writing haXe? I’d wish there was a dev tool for Eclipse or FDT would support haXe then I’d jump right on the bandwagon. But otherwise it’s currently too much efforts to change my work pipeline for that.

    1. Sadly there is no good eclipse plugin – there is eclihx, but i guess it’s dead by now since it wasn’t updated for a long time: http://code.google.com/p/eclihx/
      For windows user, FlashDevelop is currently the best choice I guess.

  3. yes, the swc file keeps all optimizations including alchemy memory.

  4. Hi, I am interested in this library but it seems your release it targeted towards as3 users, have you considered also releasing on lib.haxe.org so that it is easier for haxe users to install your libs.

    1. I’ve just added my project to lib.haxe.org – had problems submitting the project using the the updated haxelib.exe.

  5. Hi Michael,

    i only have to say “THANK YOU” for your great work. It’s a pleasure to work with your libraries.

  6. Great article, thank you for putting all of this information together.

Trackbacks/Pingbacks

  1. [...] Dieser Eintrag wurde auf Twitter von Michael Baczynski, dominic mck erwähnt. dominic mck sagte: awsome datastructs RT: @polygonal: data structures released http://tiny.cc/DdrJ7 [...]

  2. Social comments and analytics for this post…

    This post was mentioned on Twitter by polygonal: data structures released http://tiny.cc/DdrJ7

Get Adobe Flash player