Flash Frameworks Revisited

On my long list of plans for this year was to dive into the world of Flash Frameworks.
Only thing is that it has taken me so long, that the world has moved on to Flex Frameworks, but that’s beside the point.

I wanted to dive into frameworks because I heard all these people talk about how great frameworks are and how they’ve helped people build great applications etc.

A quick recap of my first impressions/experiences:

  • there are a LOT of frameworks, think of PixLib, Guggaf, Vegas, PureMVC, ARP, etc. And they are all open source (at least most of them).
  • although these frameworks are open source, most of them are one or two man shows, instead of joining an open source framework project, people rather start writing their own framework. So much for open source, so much for improving existing frameworks, so much for building our own ego in the who-gets-his-framework-0.2-alpha out the door first :).
  • some frameworks are more heavily promoted than others. I’ve seen developers urging people to download a framework a couple of 1000 files big, so they could it’s the Delegate class. An image of a big cannon comes to mind…
  • the available collection of frameworks is like a fruitbasket, some of the frameworks are structural, other are graphical (as in GUI widgets), some are utility frameworks (with features such as logging), some are animation frameworks, some are a combination of any of the above.
  • some frameworks are completely overkill, over the top with so many files that you’ll have written what you need long before you’ve found it somewhere else.
  • documentation on some frameworks is minimum and documentation that is available is badly written, spelled or structured. I probably shouldn’t get annoyed by that, but bad spelling and half english documentation is like a dented car with half the pages torn out of the manual, the engine might be good, but I wouldn’t feel overly confident driving it.
  • the quality of the code is not what I had expected. For example take such a simple thing as _global.ASSetPropFlags. I don’t think calls to functions like that should be spread over your code base. Beside being poorly documented, I saw things like almost empty template classes with a 100 lines of comments in a // // // format, taking up a lot of space, but conveing nothing. Classes that juggle around pointers, prototypes, __proto__’s, and in general are not KISS (Keep It Simple Stupid). Variables names such as i, i2, a, _n, _i are not uncommon as well.
  • the architecture of the structural frameworks was disappointing. Some use a lot of Singletons, declare everything as Object, store almost everything in hashtables under string keys so it can easily be located (or never found), and reverting back to getters and setters as type fooling tricks. If effect it negates type checking and self documentation of the code. Some frameworks are based around the view. And the view as your main application class? I thought we only did that in Visual Basic 3, where structured OO programming was nearly impossible anyway? In general what I found was that some frameworks offer quick tricks, and in doing so providing more of a write time convenience then a read time convenience. I could go on about what I don’t like about each structural framework, but that might it sound like a flamewar (framewar’ bwahaha!). This is not my intention. I merely meant to say that my high hopes of finding the GoldenKey Framework quickly went out the window (for those that are not familiar with the term Golden Key, it refers to an object that if found would unlock a person’s highest skill in a certain area, as if there is a trick to learning how to rock on the guitar, or draw like a pro. Or program as if you have 20 years of experience for that matter).
  • I am amazed at the popularity of some frameworks and the praise they receive, when in my eyes using them violates a number of good programming practices.
  • structural frameworks need not be that big. Utility frameworks often are bigger, and widget frameworks bigger even.
  • structural frameworks form the core of your application, the first thing you look at when you need to figure out how an application works is the structure. It is the most important thing to have right if your building a large application.
  • A software project is like a house in someways. It has a foundation and walls (structural framework), it has doors and windows etc (the interface widgets, and a nice layer of paint to go with it), and once you enter it, it has stuff for you to sit on, cook with etc (the utility framework). When you decide to refactor erm sorry redecorate your house, it’s easiest to throw some utility stuff out and get some new in. Changing the way your house looks might be a little more work (visual) and expanding your house to accomodate your growing kids etc might be the hardest of all. Point is that a lot of quick wins could be made in our project by improving the utility classes it uses first. Improving the visual widgets and structure of the application is more daunting, and thus we spent our time on developing our own utility framework first, and well to be honest we decided to handle what we knew how to handle first and then get back to the rest.
  • after trying out a number of structural frameworks, I haven’t seen one that I like. As my colleague Paul said, “that either means we’re very smart, or just too stupid to understand what we don’t understand”. Well that might be case, but I’d like to prove myself wrong first.
  • utility frameworks might offer a lot of quick wins and might be incorporated easily, since they tend to be less coupled then structural or widget frameworks (but I haven’t found one that I liked either)
  • I kept wondering if I didn’t like what I saw since I didn’t write it. But after seeing code written by my colleagues which I did like, I decided that that wasn’t the case :)
  • Okay SO what is it that makes me doubt whether the existence of a structural framework (that I like :) ) is even possible?:

  • I think that One Size Fits All is an illusion. Something that works for a very small application might not work for a very large application, and vice versa it might be overkill.
  • design patterns don’t make a framework. If there is a problem building bridges and a structure is devised which solves this problem, does that mean each bridge can be built from the same halffabricates? Or does it simply mean that if you do your calculations right, as taught by the structural solution, and you built it according to an engineering plan, with carefully selected halffabricates tailored to your bridge, your chance of success is bigger? In other words, being able to tell someone how they can best structure their application, doesn’t mean it is possible to provide him with base classes as well. However by telling them how they might structure their application, they’ll be able to write the base classes they need to support that structure.

That being said, another thing that doesn’t help is the diversity of applications that are being built:

  • applications with straightforward point and click interfaces
  • applications driven solely by the data they receive
  • applications that have to externally configurable
  • applications with flashy views dancing around on the screen vs simple boring views
  • applications consisting of communication plugins or subapplications
  • applications with different UI’s (commandline vs GUI eg)
  • applications with subsubsubsubviews instead of a simple list of main views
  • applications that are simple and small (eg small games) built once and never looked at again
  • applications that are larger systems that have to run for years on end and are critical for the business
  • etc etc

Okay but that was last year (this is all SOOO last year!), so why am I writing this now? One of my colleagues (Erik) came up to me last week asking for some progress information on our company’s structural framework. “Erm sorry dude, haven’t started yet. Busy with the utility classes and all.” (His project is still in AS2 too btw. I’ve seen some rants from people that don’t understand why you’d still want to program in AS2, but I myself don’t see the rush to AS3. In my opinion if you program well in AS2 and the migration is not required by the technical/functional/performance requirements, I don’t see why I’d wanna migrate. I’ve seen a number of things about AS3 and Flex that do not necessarily make me a happy camper, so I for one am not going to migrate a 500 swf project purely for the environment or new language features. FlashDevelop/MTASC makes me VERY happy so… :) And no I’ll not get into what I don’t like bout AS3, this post is getting long enough as it is).

Anyway I’m getting sidetracked again. As Erik and I continued our discussion he informed me he was looking into PureMVC and that it looked promising. We decided it might be a good plan if our other flash fanatic (Paul) and me looked into it as well, so that we might finally decide on a structural framework. So we did. And we didn’t like it very much. Since I haven’t read a negative note on the internet about it yet, this means we are probably not smart but very stupid as Paul succinctly put it. Which is kinda worrysome to be honest :). Anyway nothing to lose sleep over. We watched the SilvaFUG Flex Application Frameworks Presentation (http://www.asserttrue.com/articles/2007/10/17/silvafug-application-frameworks-presentation), and they presented another option, that we hadn’t considered as a real alternative before, assuming that in the end we would have to settle on a framework. That option was “None of the above”, as in “do everything yourself”.
They said that:

  • they’d done it before
  • it can be fine for developers with a deep understanding of GUI (? why GUI?) design patterns
  • it’s not trivial for new users
  • documentation might be lacking

So there is still hope, we might just have a deep understanding of design patterns (or not…). In addition it might not be trivial for new users, but come on if I look at any of the existing frameworks and their documentation, are those trivial to understand? And once you understand their structure, does that imply you’ll be able to jump into existing applications right away? The samples are always small, so do these frameworks really tell you how to deal with all the nitty gritty architectural issues of big applications with nested views, asynchronous views & models, etc?

So what to do? Instead of whining about it, it’s probably best to try and do it better. But honestly I’m not sure if we can. Cliff Hall did a tremendous job on PureMVC, with lots of documentation and samples. It’s easy to point out the things that itch, but it’s much harder to make that itch go away.

We decided to assume that the examples on the PureMVC site are considered to be good examples. Good examples of the day to day use of the PureMVC framework. Following that line of reasoning, we think it is valid to point out the itches in such an example and try to do it another way.
This is not to thwart PureMVC, I’m sure it works just great for a lot of people. Looking at the resulting applications however I just don’t feel the click I hope to feel when I finally nail that structure down for myself. During the past few years I’ve been writing multiple applications, and each had an architecture tailored to that specific app. Having to think about that and having to come up with such an architecture (and having a lot of deja vu’s) itches as well, and it’s incredibly tiresome.
The combination of not being able to find what makes us tick in other frameworks, nor in our own applications, drove us to insani… erm drove us to do battle! The Battle of MVC application structures!

In practice this means, that Erik, Paul and me have all agreed on rewriting the Cafetownsend example as we think such an application should be structured. In AS2 :) To be honest I spent the first two days after that decision pulling out the hairs on my head (literally). But as days go by, I’m getting more and more excited to bite down on what I’ve been wanting to do for a long time, without fearing failure (not that I’m sure I won’t fail, I’m just not afraid to so :)). Erik and Paul are both very likeable persons and if nothing else it means we’ll get a good laugh at least every other friday when we’re together discussing our monstrosities).

Coming to think of it, I haven’t been able to find one actionscript MVC example I like… zomg I’m doomed. However I’ll post what we come up with here, so you might see and decide for yourself. We’ll include as much design decisions and discussion of those decisions as possible. I’ll dive into what itches in the PureMVC examples in my next post. I’ll ask Cliff for his feedback on those points as well, since there is ofcourse still the rather large possibility that we’re simply missing something.

What’s the battle element you might ask? Well:

  • implementation speed
  • structural clarity
  • self documentation
  • maintainability
  • adaptability
  • safety of changes (how safe is it to change your application without being afraid it breaks)
  • testability is kept out of the loop at the moment but we might throw it in as another challenge in the future

The idea is to finish the basic application first, documented with all pro’s/con’s & design decisions and then propose changes to eachother. “What if your view had to slide in instead of just being set to visible? What if your view had to be loaded dynamically at runtime instead of…? What if your model was asynchronous? What if a view consisted of multiple subviews? What if what if what if…”. The challenge for us is to see which solution supports the cleanest implementation and why.

In addition my idea is to build the application in clearly defined phases as much as possible, to promote a division of labour whenever possible. As more and more demands are made in terms of what-if statements, refactoring might be needed, so it will be clear which requirements forced a refactoring of (parts of) the application.

And with that, my dear readers, I’m off to enjoy the rest of my free saturday evening, which lasts exactly -2 minutes from now.

ps I just downloaded the PureMVC and Cairngorm examples from http://www.asserttrue.com/ and I was able to understand the cairngorm example almost instantly, while the PureMVC one took me some time. I think this might mean that the mental image I’ve formed of application structures over the years is just closer to the one presented in Cairngorm than it is in PureMVC. But just a short example of something that itches: there are 2 events, StartUpEvent and AddTaskEvent. They both have some public fields defining the events types. However if by accident the content of those public fields is the same, your application won’t work anymore. This means that you have to be aware of all event types over all event classes to avoid this issue. At least in this example, I’m not sure if it’s inherent to Cairngorm, or just this example.
Another thing, the central event dispatcher. There are scenario’s where it might be necessary to have a message bus, to dispatch events to objects that should be unaware of eachother, but I don’t know a global eventdispatcher, with a controller that doesn’t have to know where his events come from? I have a controller for an event, who fires it? Oh I don’t know I’ll just search through the codebase?

3 Responses to “Flash Frameworks Revisited”

  1. Cliff Hall Says:

    Hi Hans,
    I’ll try to touch on the bullets you outlined, but you raised a number of other issues here and there as well, that could lead to a response longer than the post. If there are nagging parts that you’d like to know more about, please feel free to post in smaller chunks at http://forums.puremvc.org.

    * implementation speed
    I don’t know where you are on the learning curve, so your impressions at this moment may change drastically over the next few apps you work with.

    It is impossible for their not to be a learning curve at a certain level of complexity, and every problem has a minimum level of complexity required to solve it. The associated learning curve has to do with how optimal the solution is and how well it’s documented. It is a challenge, but no amount of the latter can make take up the slack of poor attention to the former.

    Speaking for myself, being up the curve a bit, I find that implementation speed is faster than its ever been for me on any platform or language in years. This is not hype, I’ve just gotten what I set out to do done. A simple framework for ME to build apps with.

    * structural clarity
    I’ve seen a few ‘why do you even need a framework, you can write loosely coupled code yourself and do just as well without’.-type posts. I agree with that to some extent for those with the knowledge to structure things well to begin with and plenty of proven ideas about how to to do it right.

    But I wanted something that people who have less background with patterns and how to mix and match them could still take advantage of the classic MVC meta-pattern. Unfortunately the meta part means there is no specific set of actors dictated, no specific collaboration patterns only very high level indications about how the regions should talk to each other.

    This means some actual patterns had to be chosen and implementation modifications made to make them do the meta thing as well as being extendable and easy to use. A challenge, and I’m sure that like orderly patterns on the Rubic’s Cube, there are any number of other answers to this problem that would be equivalent or more interesting than the one-color-per-side answer I’ve offered with my solution.

    The key is that it be orderly, and a lot of folks including myself have perceived it that way, so thats positive. All the rough edges have been pointed out and debated and 2.0 will make it have even more clarity and completeness without seeming to have been visited by the creepy feature creature. The goal is still to reach stability and stop. Simple scope does not need continuous reevaluation.

    * self documentation
    By self-documentation, I’m assuming you mean that the methodology is implicit in the code, *reducing* the need for ASDoc style comments to tell you what’s going on. I find that a lot of the PureMVC code that I see from others looks very much what I write myself. The variance is in the problem domain. This gives me a good indication that the idioms are clear (and getting a even clearer with 2.0).

    * maintainability
    Since the methodology is so implicit in the coding (i.e. the roles, responsibilities and collaborations are well-defined) this means adding functionality later is as easy building it in when you started. Other developers familiar with the framework are able to quickly get up to speed because they only need to know the business domain of the app and an overview of the implementation.

    * adaptability
    The fact that it’s being ported successfully to AS2, C#, Java, PHP, ColdFusion, and Python are good indications that it is adaptable. For instance here is a C# Silverlight port:

    http://www.mattbrailsford.com/PureMVCLoginDemo

    of the this Flex/WebOrb demo: http://www.websector.de/blog/2007/08/10/another-weborb-for-php-login-sample-using-flex-and-puremvc/

    Both PureMVC, both using the same client application classes and structure.

    * safety of changes (how safe is it to change your application without being afraid it breaks)
    Again, it has to do with where you are on the curve, and how good your debugger skills are. But it’s sweet in the flex debugger because you set a breakpoint, open your facade see model, view, controller. Open, say view. You see all the registered Mediators. Open the ApplicationControlBarMediator, say. You can see its view component the ApplicationControlBar. Open it and inspect all its properties. Or dive into the proxys of the model in the same way.

    * testability is kept out of the loop at the moment but we might throw it in as another challenge in the future
    PureMVC has full FlexUnit tests. The same testing problems that exist within all flex apps exist unabated, but you can still test the things that it makes sense to test.

    And there are utilities being built right now by myself to analyze a running PureMVC app. Think intercepting facade.

    Laters, food’s getting cold.

    -=Cliff>

  2. Steven Sacks Says:

    I just discovered this post on Jesse Warden’s review of PureMVC. Given your depth of discussion on the topic of Flash frameworks, I’d certainly welcome a review of my Gaia Framework by you. I’m always looking for ways to improve it! :)

  3. Hans Wichman Says:

    Hey Steven,

    I’ve downloaded your framework a couple of weeks ago and up to now working with it has been great fun (but no tangible results yet). It’s definately not the kind of framework I had in mind when I wrote this post, thinking more of backend frameworks, which just goes to show how easy it is to get tunnelvision, since your frontend framework is going to be a huge timesaver . And as you well know yourself the two don’t exclude each other.

    The whole puremvc evaluation ended when a very large post wasn’t that well received by the creator of puremvc. Seeing I didn’t have the time to improve the quality of the post and defend all it’s points and realising it wasn’t going to change puremvc anyway I decided to trash the 14 page rant:)) and decided to do my own thing. So we’re currently at iteration x of cafetownsend in our own backend framework. Reading your posts on flashcoders your probably gonna find a lot of it overkill:) but nonetheless it might be fun to have you take a look at it.

    Anywayz I’m getting sidetracked: I got gaia on the comp, and will spent a lot of time next few months building stuff with it. Up to now it rocks, and if I find anything to improve I’ll let you know (but tbh I don’t think I will, you seem to know your stuff very well). In any case I’ll read the docs before posting on the forum unlike I did last time :).

Leave a Reply