An Architect's View

CFML, Clojure, Software Design, Frameworks and more...

An Architect's View

I think I "get" Cairngorm!

October 19, 2007 · 18 Comments

Every time I've looked at Cairngorm, it's always seemed complete overkill to me. It's why I was so pleased to see Joe Rinehart start working on Model-Glue for Flex. Cairngorm made Flex development look much harder than I wanted to believe it really is. It's been years since I had to build desktop applications with a full event-driven, multi-threaded architecture and I finally realized on the way home from MAX Europe that web development has truly spoiled me. Web development - by which I mean pure HTML application development - is so much simpler than desktop development.I'd been trying to approach Flex from that point of view as well. On the way back from MAX I started to build a Flex version of my startup's website. This is actually the second time I've tried to do this. The first time was not a very successful experiment and, at the time, I wasn't really quite sure why. This time I was following the information I'd learned in Joe Berkovitz's sessions and so I knew I'd have multiple controllers, multiple services and multiple models and that I'd be using events a lot. It meant I'd be writing a lot more AS3 classes and trying to do a lot less in MXML. It was at that point I finally realized why Cairngorm uses command objects everywhere: it's the easiest way to get an asynchronous remote method dispatched and still provide a stateful hook for the result handlers (since you can have multiple concurrently active requests to the same remote service). Of course, it doesn't really need command objects per se, it just needs a context for each async call. A command object is just a reasonably convenient way to package that. As I've done in the past, I'm going to have to work without a framework for a while and experiment with different design patterns to get a feel of where the pain points are for me and then decide what to do about them. I still don't like Cairngorm but I do at least fully understand the problems it is trying to solve and how it does that. I like the approach that Allurent takes (see Joe Berkovitz's slides and code from MAX) and I like where Joe Rinehart is going with Model-Glue for Flex. Not sure if it'll make a Cairngorm user of me (if Flex Builder 3 auto-generated all the boilerplate code for Cairngorm I might be more tempted) but it will definitely - finally - make a Flex developer of me. Now excuse me, I'm off to download FlexUnit so I can start doing some test-driven Flex development!

Tags: flex

18 responses so far ↓

  • 1 João Fernandes // Oct 19, 2007 at 3:26 PM

    Sean, there is also pureMVC framework if you want to take a look into.

    http://www.puremvc.org
  • 2 Brian Rinaldi // Oct 19, 2007 at 3:32 PM

    In case you are curious a coworker and I wrote a Cairngorm walkthrough for the recently released Fusion Authority Quarterly Update.
  • 3 Mike Hattington // Oct 19, 2007 at 3:53 PM

    Came across a good breezo today comparing various Flex frameworks.

    https://admin.adobe.acrobat.com/_a200985228/p12266504/

    They seemed to like PureMVC. You had a strong influence on our company going with MG in the CF world, so as we transition to Flex interested to hear your thoughts going forward.
  • 4 Brian // Oct 19, 2007 at 6:19 PM

    I would definitely suggest looking more into component-based architectures using Flex before exploring frameworks like Cairngorm, PureMVC, or MG:Flex. In our shop we've been down the Flex framework road for multiple projects and we have yet been satisfied with the resulting applications. We can't seem to get around the idea that the majority of the frameworks circumvent the facilities provided to you in Flex for their own alternative mechanisms.
    We've begun exploring the use of Flex components as a mean by which to abstract the hooks into the services in our SOA and are having some great success thus far. We are trying to research component-based architectures in other languages (e.g. - OSGI in Java, .NET components, et) as well to get clues as to how we could take advantage of what Flex provides for component design. Language level properties, baked-in event handling, and stateful behaviors seem to be the common elements in a lot of these approaches. We're hoping we can connect the dots and fully realize the benefits of Flex components before exploring any further work with frameworks.

    Just my 2 cents I guess, but I thought I'd share.
  • 5 Sean Corfield // Oct 19, 2007 at 7:03 PM

    @Joao, Mike - thank you! I'd heard of PureMVC but not looked at it. Now I have the ZIPs downloaded and have watched the preso (well, the slides at asserttrue.com) and downloaded the comparative code.

    @Brian Rinaldi - great, it's on my "to read" list but time hasn't permitted yet!

    @Brian (no surname) - sounds like you're still wandering in the "no framework" realm so please keep me posted on your findings since I too like to understand the landscape before settling on a handful of frameworks for my (paying) work.

    The reality is that Cairngorm is so widely adopted I probably can't avoid it but learning MVCS and PureMVC certainly won't hurt - and anything else that comes along that gets any broad adoption won't hurt either.

    Thank you all - please keep the feedback coming!
  • 6 Maxim Porges // Oct 19, 2007 at 7:30 PM

    Hey Sean - great post.

    Personally, every Flex framework I've used so far has felt "wrong", in the sense that Flex provides everything you need to build great layered apps, leaving very little to be desired. Strapping a framework on top just seems unnecessary to me in every way.

    As an example, we build all of our Java apps at CFI using Spring. Spring is a framework in the sense that it helps our objects find each other and provides some convenience libraries, but it really has zero impact on the design of the application (one of the things that makes us like Spring so much). You just have a bunch of nicely designed objects talking to each other in a layered fashion, implementing industry-standard best practices and a design pattern or two where appropriate.

    My feeling since we started building Flex apps is, there's no reason why our Flex apps should be any different to our Spring apps, with the core Flex libraries taking the place of Spring (at least as a set of convenience APIs). The beautiful marriage between MXML and ActionScript makes it possible to do some really neat things, and you can write nicely designed objects talking to each other in a layered fashion all day long in ActionScript 3 with no regard for a framework of any sort. Without having to worry about page rendering and server roundtripping, you can maintain state, and the event model in Flex plus the simple implementation of powerful data binding puts any other desktop development paradigm I have used to shame. And yes, I say desktop, because I think the best way to think of a Flex app is as a desktop app delivered over the web.

    So, IMO, therein lies the key issue with Flex frameworks: I feel that they are mostly based on principles taken from web frameworks, whose development and design was driven by years of pain with the stateless nature of HTTP and the round-trip chatter of HTML-based web apps. These problems simply don't exist in Flex; you have a stateful client, and the data service architecture/data push neatly abstracts the fact that your local Flex app is running on a diffferent machine to the server from which it was spawned.

    I think it's natural for web developers to be the first to embrace Flex, and thus for them to assume similar solutions to previously common problems from the web development arena, but I just don't think the problems are there when you're working with a stateful client. I kind of feel like the early adopters deceived themselves, and that in the end, we'll find that much less is needed in terms fo a Flex framework than was originally thought.

    Brian and I are working along with the other guys at CFI to debunk the whole need for a framework in Flex. We'll certainly keep blogging on our discoveries, and are interested in any input the community may have.

    - max
  • 7 Maxim Porges // Oct 19, 2007 at 7:41 PM

    As a follow up, not sure if you have any interest, but I <a href="http://maximporges.blogspot.com/2007/05/flex-frameworks-nothing-but-pain.html">blogged a little on the pain with Flex frameworks</a> some time back. It's been a few months, and since then I've felt better about where we're headed and more certain that it will work nicely (as my last comment indicated).
  • 8 Sean Corfield // Oct 19, 2007 at 9:04 PM

    @Maxim, thank you - this totally confirms my gut feelings about Flex and frameworks but there still seems to be a gap between what Flex offers and what we need to create easily maintainable applications with no repetition of code...

  • 9 david_deraedt // Oct 20, 2007 at 2:18 AM

    Sean, I think I know exactly how feel.
    Though, at one point, I decided to go with cairngorm because I thought that using a framework that I didn't really get was better that not using no framework at all.
    As time went by, I started to actually love it (though of course it has it flaws).
    The main problem to me was the huge amount of code I had to write for each application.

    This is the reason why I looked for code generators. Most of them were usefull, but they either didn't do half the job I wanted them to do, or did things I didn't want them to do.
    So I decided do create my own cairngorm code generator (as an AIR app), and so far it works great. I only have to provide it with remote services and value objects (only PHP so far) and it creates all my base code.

    I'll be releasing a preview in the coming days, you can check my blog for more info:

    http://www.dehats.com/drupal/

    I'm also looking forward to try PureMVC, which looks very interesting.
  • 10 Kyle Hayes // Oct 20, 2007 at 6:19 AM

    If you are looking to generate Cairngorm code, take a look at this:
    http://www.tylerbeck.com/CairngormCreator/
  • 11 John Farrar // Oct 20, 2007 at 6:39 AM

    Well since we are now public with COOP I am looking at how to integrate our COOP applications with Flex/AIR apps also. One of the things we found in COOP (just our opinion) was that many of the frameworks passed over the power of ColdFusion on the way to OO. With that said Brian made a comment above that sounded like he was thinking along the same lines. Flex is not Java and it seems that many people forget that different platforms actually think different no matter how many ways they think alike. Then they create work around patches to make frameworks think like Java frameworks. This isn't all bad, but when we forget the power of the platform we are in this can stagnate creativity pushing for a purist view of duplication on a different platform. ( IMO )
  • 12 sal // Oct 20, 2007 at 8:42 AM

    So let me get this straight, Flex, (a client side technology(MXML)) that compiles into a swf, has it's own MVC-ish style framework, that recieves data from say a backend rails/MG application (if the need exists)...? Damn that seems too much for an application?? How many damn layers can there possibly be? Correct me if I'm wrong...
  • 13 Elliott Sprehn // Oct 20, 2007 at 9:23 AM

    Without getting into the "To framework or not to framework in Flex" debate here, as a little clarification, I think it should be noted that Flex is single threaded. Rather, all flash is single threaded. This is even true of Apollo applications that use Webkit (which is also single threaded).

    It's due to this that developers need to be particularly aware of what methods can block for long periods of time and how to use the Async variants of classes and methods.

    So even with Flex you're still "spoiled" in the sense that you can't get run into the plethora of issues related to multi-threading in a complex application. That's not even true for "pure HTML application development," provided you're using JSP or CF.
  • 14 Kyle Hayes // Oct 20, 2007 at 10:40 AM

    @sal - MG, Mach-II and Fusebox are only for strictly CF applications. When you use Flex, you actually only interact with the Service Layer of your API. So the controller of the app is in Flex, not CF.
  • 15 MrBuzzy // Oct 21, 2007 at 3:42 PM

    On generating the boilder plate stuff, there is also Cairngen: http://www.ericfeminella.com/blog/cairngen/ sorry, haven't tried it.
  • 16 eh // Feb 11, 2008 at 12:36 PM

    Maxim - I understand where you are coming from (and I find it very nice to see someone willing to question "the way you're supposed to do it"), but I think you're thinking of Cairngorm the wrong way. Even "normal" client software has certain architecture patterns and "best practices", and AFAIK probably the majority favor an MVC like pattern.

    Cairngorm gives you a standard way to achieve that separation of M, V and C. Without it you could end up with controller code in your view mxml, model data stored in your controller code, and so on, unless you're careful. But why waste our brain cycles on that problem? Using Cairngorm it becomes almost a thoughtless effort. And the nice thing about it is that once you get used to it (actually use it in a project or two), it suddenly seems very simple and automatic.

    And I like the way you describe a Flex app - a desktop app delivered over a network. I think of it exactly the same way (kind of makes you wonder if it shouldn't be called a traditional "web application"!)
  • 17 Sean Corfield // Feb 11, 2008 at 1:17 PM

    @eh, MVC is "just" a pattern and Flex lets you implement that natively. With Cairngorm, you can still create messy code. Frameworks don't prevent badly structured code nor do they automatically mean your code will follow any given pattern. Frameworks are supposed to reduce the amount of work you do by taking care of repetitive tasks for you. Cairngorm occupies a weird space - not quite a full framework and yet more than just an architecture - and it makes you write *more* code, not less.
  • 18 Maxim Porges // Feb 11, 2008 at 3:04 PM

    @eh,

    I think you are misreading my position. I fully understand MVC and its benefits. What I don't think is that the front controller pattern applies to Flex development, and that's basically what Cairngorm makes you do. It also requires you to write a ton of (IMO) meaningless boilerplate code that provides zero value, instead of using the built-ins in Flex which provide the same functionality (such as event dispatching).

    I'll be presenting on this very topic at cf.objective() 2008 in May, and I also have <a href="http://maximporges.blogspot.com/2008/02/fun-with-dynamic-classes-in-flex.html">some upcoming news on my blog</a> regarding a different way to build Flex apps.

    - max

Leave a Comment

Leave this field empty: