Flex & Rails: Impedance Mismatch
February 21, 2008 at 23:49 To Flex or not to Flex that is the question. Well not really but I woke up one morning and decided that I wanted to learn a little bit more about Flex, the rich application framework by Adobe. So I bought this recently published book called Flexible Rails. Though I don’t like the style of the book (it’s like one big code walk-through) it did manage to give me a good feel for what Flex programming is. Though I find Flex to be a nice piece of technology, to me it lacks a simple feature to make it really usable with Rails: dynamic code execution ala “eval” in Javascript.
The Good
Flex is the “fat” client for web applications. With Flex you can produce really good looking GUI with the type of interactions that you would only expect from a heavy desktop application. That type of interface is not easily built with the HTML + CSS + Ajax combo. Furthermore, with Adobe AIR coming out, Flex applications will even have access to the local file system and other resources.
The Bad
I think that in moving from interpreted to compiled code, Adobe has made one important mistake: they removed support for eval, which would have required “compile on the fly”. Sure there are some partial alternatives out there but none equal eval. Furthermore, Action Script is a strongly typed language, which means that you need to tell the compiler everything in advance (no duck typing here). Depending on your point of view this might actually be a good thing but from a Ruby programmer perspective, it’s not.
The Mismatch
Sure thing, you can make your Flex applications talk to Rails but the fact is that the programming style in Flex is reminiscent to Java programming. To take a Rails analogy and assuming that you’re using the Cairngorm library (MVC on the client side) here is what you need to do in your Flex application:
- Declare each model in the client (using a Plain Old Flex Object for example)
- Declare/Dispatch events that are likely to happen with these objects
- Implement a model locator (the local store for a given model)
- Implement a broker (business delegate) between the client-store and the server
- Code methods that translate between server/internal representation
Have I forgotten anything? That’s lot’s of code for little result and when you look at it it’s even worse. This is the type of code that screams “generated me” or “generate on the fly and evaluate” but for now we seem to be stuck just like Java was before the tools started generating most of the code for us. When you have more generated code than actual code, then you know that you’d be much better off with a dynamic language like Ruby.
So in my opinion, Flex allows you to do really nice front-ends and you can make it play nice with Rails. The problem is that Flex programming is not natural to the Ruby programmers. As a java programmer you might feel right at home but as a Ruby programmer it feels awkward: it's just to verbose and thus the impedance mismatch. If you don't mind the awkwardness then Flex will allow you to go beyond what traditional can do today. But please keep in mind that I’m not a Flex expert.
Your Opinion
- What do you think about Flex?
- What about the Flex + Rails combo?
- Could anything be done to make the match better for Ruby programmers?
References (1)
-
Related: Flexible Rails Blog

Reader Comments (1)
hey
Really nice tips!
will try to keep it in my mind
thanks!