Wednesday, January 7, 2009

AS3 IOC Containers: Spring Actionscript (Prana) vs Parsley

Today, I decided to bring some good ol' IOC and dependency injection into my AS3 workflow. I took two of the most popular IOC containers for test drives and compared the features of both, and in this post, I'm going to log my findings.

1. SpiceFactory's Parsley (current version 1.0.2)
Download | Documentation

Learning to use Parsley was really easy. The documentation was very concise and yet complete, it didn't just shove a bunch of examples and ASDocs in your face, it explained in-depth how the various aspects of Parsley work and how they can be extended. It has really interesting features, kind of a little break from just regular IOC and dependency injection.

Some of the things I really liked about Parsley were:
  • The documentation. It rocked. It was so complete and so in-depth that it made it a breeze to get started with Parsley. It showed a lot of examples of how to use Parsley to its fullest, and explained the various API's well.
  • Localization of messages. Parsley makes it really easy to provide localization to your applications. Localization is one of the things that has always been a pain for developers to implement, but Parsley covers this facet extremely well. Localization can be manually set or automatically interpreted by Parsley. You create message bundles for the various strings required by your application (such as a tooltip for a button: "Opens a file for editing.") and you create multiple message bundles (which can go in separate XML files) for each locale you're targeting. It's super easy and though I haven't tried it out just yet, one can see how it makes localization a non-issue for application development. The more you take advantage of IOC in Parsley, the more you can incorporate localization. Awesome feature.
  • Event listener tags in XML contexts. You can easily register event listeners in the context with the "listener" tag. This makes life a heck of a lot easier for me at least. I despise typing out "addEventListener" four to ten times for a complicated object with lots of dependencies.
  • Easy to extend. Fo' sho'.
Some of things I wasn't so fond of in Parsley:
  • Non Spring-like XML definitions. Parsley breaks away from the Spring XML definitions that I like, and am used to. I'm OCD, so this is basically life-and-death for me ;) Plus the Parsley definition structure is a bit more verbose, so you'll end up typing more code in your definition files.
  • Inability to simply invoke methods. For the logging framework I've developed and use, I need to call functions like "registerOutput" on my objects, and Parsley simply can't do that yet. Spring Actionscript (Prana) handles this with the "method-invocation" tag, which I like... a lot.
  • More verbose setup in parsing contexts. You need to instantiate a parser and have that load a context into another object. This extra step is kind of useless, at least to me it is.
All in all, Parsley was ok but I found that I prefer Spring Actionscript (Prana) in the day-to-day stuff. Although Parsley has some really cool API's that I haven't seen yet, I like a more Spring-like IOC container.

2. Spring's "Spring Actionscript", formerly Prana (current version 0.6)
Download | Documentation

Spring Actionscript (Prana) was a bit more difficult to learn because of lack of documentation, but proved to be far more powerful than Parsley, though it lacks some of the cool features that Parsley has. As far as I know, it lacks the cool localization that Parsley offers standard, and it definitely lacks the "listener" tag that Parsley boasts, though you can achieve the same general result with the Spring Actionscript "method-invocation" node. Plus, since Spring has taken charge of the project, it's just like Spring! This, for me, is huge. I love Spring. Spring is amazing and easy to use, and their Actionscript IOC container is such as well.

What I loved about Spring Actionscript:
  • It's just like Spring. \m/
  • The "method-invocation" node. This really helps make the framework a heck of a lot more flexible.
  • XML declaration files are less verbose and AS3 instantiation is a less wordy. And it runs just as you'd expect an IOC container to run. If you've used Spring, the migration to Spring Actionscript is a no brainer.
  • It's a huge framework. I guess this is both good and bad, but I like having a lot versus a little, but maybe that's just me. It has plugins to Cairngorm and PureMVC, which I'm sure a lot of people are grateful for.
What I kind of didn't like about Spring Actionscript:
  • It doesn't have the "listener" tag that Parsley has. It's more of a convenience thing than a lack of a feature, but it's still really nice to have.
  • It doesn't have the localization features of Parsley. The message bundle API of Parsley is genius, really powerful and super easy to use.
  • Lack of documentation. Insert sad face here. It was a bit of a challenge to get up and going with it, but in the end it was worth it.
  • Lack of "init-method" and "destroy-method" and "factory-method" subtags of an "object." It supports the "init-method" and "factory-method" parameters on the "object" tag, but it's nice to just nest those underneath the "object" tag rather than as a parameter to the base "object" tag. The "destroy-method" is completely left out, though I'm not sure how that would apply in AS3, if at all. I'm really missing the "static-factory-method" tag that Parsley supports though. So maybe this aspect of Parsley is more like Spring than, dare I say, Spring Actionscript?
  • Not so easy to extend. There's little documentation beyond the ASDocs, so I wouldn't know if I could implement a preprocessor like in Parsley or anything advanced like that.
Other than that, my choice is pretty much clear: Spring Actionscript takes the TK Cup! Woot! I'm going to start using it in a real-world application and I'll post again on my findings with working with Spring Actionscript in a real world scenario. Even though I kind of prefer Spring Actionscript, it is definitely missing some of the really awesome Parsley stuff. I, for one, am a huge fan of the localization features of Parsley. So, don't automatically reject using Parsley because of this post. Parsley is an awesome framework for IOC, and SpiceFactory has done a lot of good work on it. It's definitely worth your time to check into both projects and choose which is best for each situation you run into. I can definitely see some areas where I'd prefer using Parsley over Spring Actionscript

Until then, here's my two test projects. They contain basically translations of the same general project, translated to Spring Actionscript and Parsley. The required libraries are included in each projects corresponding lib folder, though I used Arthropod for debugging and I didn't include that. They're Flex projects by the way. These are to help you make your informed choice on what to go on, rather than just depending on my glorious madness to make your decisions upon:
uploads/as3ioctesting.zip

Good luck in the wonderful world of IOC!

EDIT**
Here's a bit of a disclaimer about Parsley. Parsley does have a sort of "method-invocation" tag, though it wasn't clear to me at first. According to Jens Halm, the project lead, you can have multiple init-method tags to invoke methods when the object is instantiated. So basically, you can achieve the same result without the method invocation tag. So now my choice is more unclear. I like Parsley AND Spring Actionscript. I don't know what I'm going to do, but you can still make a choice at least :)

Labels: , , , , , ,

8 Comments:

Blogger Unknown said...

thanks for the review, and thanks for including your code. You could also have a look at lowra which has a big ioc package. Though it's really lacking a lot of documentation...

January 8, 2009 at 12:09 PM  
Blogger TK said...

I took a look at LowRA and it doesn't seem to be very powerful or flexible. If you think that it's a huge library and worth the time, I could definitely write up my findings on it, but I can't see that it's really a competitor to Spring Actionscript and/or Parsley.

Oh, and there is an updated link to Spring Actionscript, but I'm going to leave the Prana link up there:
http://forum.springframework.org/showthread.php?t=64370

January 8, 2009 at 6:12 PM  
Blogger Infiniteunity3D said...

Very Nice. Thanks for the intro. I'm about to dive into the IOC World via Spring right now.

May 12, 2009 at 8:28 AM  
Blogger TK said...

Good luck! Spring Actionscript is a really nice library, it just lacks a lot of documentation and examples, which is where Parsley excels at. Have fun!

May 12, 2009 at 9:11 AM  
Blogger peder said...

Where does the MATE Framework fit into all of this? It's not IoC, but I'm wondering if you've had a chance to form and opinion yet.

May 13, 2009 at 7:58 AM  
Blogger peder said...

Where does the MATE Framework fit into all of this? It's not IoC, but I'm wondering if you've had a chance to form an opinion yet.

May 13, 2009 at 7:58 AM  
Blogger TK said...

I haven't actually looked into the Mate framework because I can't really find any information on it :P

What I heard was that it was a compile-time IOC-like framework that allowed you to wire together your objects and drive things by events. It sounds really rad, but I just haven't been able to get any information on it, and I actually don't do too much work in Flex.

May 13, 2009 at 9:19 AM  
Blogger Think Tank Dev said...

I am stoked to try Parsley now that you made a sample file. I think I would like to have the option to do real IoC via an XML file or compile time IoC like Mate.

I have worked with Mate on one commercial project and have to say I liked it. The only complaint that I have is that there is a bit of magic in there I haven't figured out, like the DI mechanisms. Ideally I would like to borrow the IoC/DI from it combine it with the Mediators concept from PureMVC and the command structure of Cairngorm. All while having an external IoC Container to boot.

August 16, 2009 at 8:10 PM  

Post a Comment

Subscribe to Post Comments [Atom]

<< Home