RIAs, Adobe Flex, and related topics

About
Resume
Contact

April 10, 2008

PureMVC vs. Cairngorm

Filed under: Cairngorm, OOAD, PureMVC — jimrobson @ 9:24 pm

I have written favorably about both Cairngorm and PureMVC, and this has led a number of people to ask which framework I prefer. Rather than make a blanket statement that one framework is better than the other, it seems more profitable to take a few moments to discuss some of the strengths and weaknesses of each.

Let’s start by emphasizing that the two frameworks share a number of strengths. Both of them provide conventions that, once learned, enable you to build complex applications faster. Both of them lend themselves (in varying degrees) to team development. Both of them promote some level of code reuse. Both of them help you make applications that are easy to maintain and extend. Both of them will enable you to build applications that any experienced Object-Oriented developer will be able to get up to speed on very quickly. Both of them give you complete control over event flows. (When using native Flex events, you need to be aware of bubbling, and whether there is any native Flex code that is also listening for the event you’re dispatching, but each of these frameworks addresses this issue - PureMVC implements a publish/subscribe system with its notifications, and Cairngorm uses CairngormEvent/CairngormEventDispatcher.)

Having looked at what the two frameworks have in common, let’s now take a look at what makes them different. Since we’re talking about Flex frameworks, I thought it would be fun to put the comparison matrix in an AdvancedDataGrid component:

Framework Comparison AdvancedDataGrid Application

You can open and interact with the matrix here. (Building it wasn’t as much fun as it should have been, but I’ll address that in a future post.)

I’m sure there’s much more that could be said, and I hope that you’ll add your thoughts to this discussion. If you don’t want to post your comments/questions here in the blog, feel free to contact me directly.

January 9, 2008

What’s with all these files?

Filed under: Cairngorm, Flex, Rails — jimrobson @ 6:57 pm

After attending my Cairngorm presentation at the 2007 FlexManiacs conference, a co-worker (who happens to be an ardent Rails developer) expressed some concern that Cairngorm seems to be overly complex. He thought that perhaps there was too much abstraction for the sake of abstraction, and mentioned that there seemed to be a lot of small files, some of which perform parallel tasks. I took his concerns to heart, and decided to re-analyze Cairngorm with a more critical eye.

Recently I began learning Ruby and Rails myself, and I have been very impressed with what I’ve seen. So far, Ruby does indeed appear to be an exceedingly attractive language, and Rails is a massive labor-saver. However, I have learned some things that make my co-worker’s concerns about Cairngorm appear to be a little ironic.

Folder structure of empty Rails application

When you tell Rails to create a new application, it creates an application directory with no less than 37 subdirectories (using RubyStack, which runs on Ruby 1.8.6 and Rails 2.0). Scattered among these directories are 49 files - all before you write a single line of code. At this stage, the application does absolutely nothing except display an HTML page welcoming you to Rails. This is far more than is required by Cairngorm. In fact, here’s an example of a complete, fully-functional, and non-trivial Cairngorm application that has only 67 files and 21 subdirectories:

Directory structure of complete Cairngorm application

At first you may think that I am comparing apples to oranges, and I will readily acknowledge that Rails does some things that Cairngorm doesn’t (most notably, Rails helps you to manage your database tasks). However, Rails and Cairngorm are both MVC-based frameworks for building Web applications, so in principle their reasons for being are really pretty similar.

In fact, the Rails workflow is in some ways similar to the Cairngorm workflow. For example, adding new functionality in either framework often involves creating a few simple files (and perhaps adding a line or two to some existing files) with the result that both frameworks lead to multiple files performing parallel tasks. In either framework, modifying the existing functionality is frequently a matter of making simple changes to several related files (e.g., a Controller file, a Model file, a View file, and a Test file). While jumping from file to file may seem inefficient to the uninitiated, in reality this workflow is great for productivity. For one thing, it’s much easier to place and track a few simple pieces of code located in a few small, intuitively named, and logically organized files than to manage a single complex piece of code in one monolithic file - especially with modern IDEs and text editors, which make it a snap to work with multiple open files simultaneously.

There are other benefits in addition to the productivity boost, of course. In either framework, for example, you can usually modify or even remove an existing piece of functionality without having any impact on the rest of your application, because the change only affects the files that are directly involved.

Anyway, what’s the point of this comparison? The point is simply this: having lots of small, well-named files with very specific functionality organized logically in several directories is not necessarily a bad idea. While at first blush it may seem daunting, in the long run it can help to save a lot of time and promote higher-quality software.

November 27, 2007

What’s so cool about Cairngorm

Filed under: Cairngorm, Flex — jimrobson @ 9:21 pm

I’ve been using Cairngorm for well over a year now. Why Cairngorm? Well, it’s not because I think that Cairngorm is the only good way to build Flex apps. It may not even be the best way; at least two reviewers have concluded that Cliff Hall’s PureMVC is the best Flex application framework around. In fact, I’ve mentioned some of my own misgivings about the framework in a previous post.

Having said that, I do think Cairngorm is a very effective way to build maintainable applications. Cairngorm apps are very easy to modify - whether you’re adding, changing, or removing functionality. Cairngorm also lends itself to use by multidisciplinary development teams, and is sufficiently intuitive that new team members can to get up to speed fairly quickly.

Let me give you a case in point. I recently had to hand one of my Cairngorm applications over to another developer. He’s a sharp programmer, and has lots of experience with Java and JavaScript (among other things) but he had never even smelled Flex before. He spent a few days reading up about Flex and Cairngorm and looking through my application. At that point, he was able to be productive immediately. Without any coaching from me, he implemented no less than three new pieces of functionality in a very short time - which is testimony to how intuitive Cairngorm is.

Another point to be made is that while the other developer was adding new functionality to the application, I was debugging some existing functionality. The fact that the application was built using Cairngorm made it very easy for us to work concurrently without getting in each other’s way.

And that’s what’s really cool about Cairngorm: for all of its warts, it does make applications very easy to maintain and extend.

But as cool as it is, I’m still not ready to commit to using it exclusively. I’m going to be taking a deeper look at the other frameworks - particularly PureMVC - and see how they compare. Stay tuned.

August 5, 2007

FlexManiacs files - better late than never

Filed under: Cairngorm, Flex — jimrobson @ 2:43 am

Well, I finally posted the files from my FlexManiacs presentations. I was hoping to have the source files completely documented before posting them, but I’ve been busy moving my family to Rhode Island (it isn’t easy to move a family of 6). I still plan to add the documentation, and to extend the sample applications further, but I think that they are useful in their current state. You can get the presentation slides and sample apps here.

The FlexManiacs folks, meanwhile, posted a Connect recording of my Modules presentation. The sound quality isn’t great (I didn’t stay close enough to the pc mic), I talked too fast, and I said “um” too many times, but in spite of all that it’s probably still useful. I recommend advancing the play head to about the 2 minute mark, because everything before that is just me getting set up and the audience getting settled in. Anyway, you can see and hear the presentation here.

Update: I put together an extremely simple Cairngorm app for one of my FlexManiacs presentations, “Using the Cairngorm Framework.” The app was so simple that I did not think it worth posting for download, but then I received a request for it. I figured that if one person requested it, then others may find it useful as well, so I uploaded it. You can get it along with my other FlexManiacs materials from the downloads page. (As an aside, this incident points to the need for blogs such as S.A.S.S.I.E. - sometimes you just need a simple example.)


Powered by WordPress