I’ve spoken on past occasions about how un-excited I am about E4X (ECMAScript for XML) with regards to ActionScript 3. Macromedia (now Adobe) made a strong push for XML for 3 player versions. Flash Player 5 had both a built-in XML parser as well as the XMLSocket connection. Flash Player 6 greatly optimized the XML parsing routines and Flash Player 7 did it again.
Problem was, for application developers dealing with nTier systems (fancy way of saying connecting to various backends), XML wasn’t the most succinct way of communicating, and those messages sometimes were a non-portable, made up language. By then, I was delving into the worlds of WebServices and Remoting. While SOAP implementations utilize XML in the underlying guts of how it works, you as the developer certainly feel like you’re writing regular code talking to code on some other server.
So, in building a prototype app using Flex 2, Cairngorm 2, and Ruby on Rails, I’m dealing with copious amounts of XML. I feel like I’m in middle-school again. It frightens me to hear myself say that as that same arrogant, holier-than-though attitude of non-big-company technologies is what I used to loathe when talking to Enterprise programmers. I can remember not just me, but countless others accomplishing a lot with just XML strings parsed by hand with very effective outcomes.
Either way, the thing that is different now is that I have E4X at my disposal. I’m the only one on the planet who feels that the old syntax is ok to use instead and isn’t overly verbose. I guess growing up with firstChild.childNodes makes you numb to the pig-latin you speak in code to get at your data. E4X, unintentionally, I perceived as more verbose because I am trying to learn as well as all the ActionScript 3 packages, mx packages, and countless other new API’s & methodologies at the same time. Spending 40 minutes on getting a new for each loop to work, referring to the docs twice, is all the temptation I need to say, “Fuggit, the old way works just fine, I know it well, and it’s faster at runtime than E4X anyway… why bother with this bs when the syntax isn’t that much cleaner?”
Many would disagree. I debated with the top Flash minds twice in the past, all with next to no support. Many fawn over it. While I was visiting my boss in Des Moines, Iowa, he took it upon himself one evening to show me some refactored XML to E4X code. He was overjoyed… I didn’t care. Granted I was happy he was happy. He went from 5 verbose lines to 3 cleaner ones.
“Ok… you’re still parsing… parsing blows.”
I don’t have a choice with Ruby on Rails. Maybe I do, and don’t know it. There is so much stuff I don’t know about ROR, but I’m going with what I got, and what I got is a consistent and readable messaging schema between Flex and Rails. Rails sends easily understood XML messages, and the ones I send to it, it can read just fine. However, after writing my Delegate to speak the CRUD methods to my Rails controller methods, I really wasn’t looking forward to writing a gigantic Factory class to convert Rails XML messages to Array’s of Value Objects, and vice-versa.
I’m still not, but found a really easy way to implement it. And thus, I get to why E4X doesn’t suck… I didn’t know it, but E4X supports binding, just like Flex does for binding variables to other variables. Suddenly, my ValueObjects who already implement a toString method to ease debugging:
public function toString():String { var s:String = ""; s += "[class ProjectVO"; s += " id=" + id; s += " projectName=" + projectName; s += " updatedDate=" + updatedDate; s += " creationDate=" + creationDate; s += " ]"; return s; }
Now have a nice way to get their XML equivalent:
public function toXML():XML { var updatedDateString:String = DateUtils.getRubyDateString(updatedDate); var creationDateString:String = DateUtils.getRubyDateString(creationDate); var xmlified:XML = <project> <updated-date type="date">{updatedDateString}</updated-date> <creation-date type="date">{creationDateString}</creation-date> <id type="integer">{id}</id> <project-name>{projectName}</project-name> </project>; return xmlified; }
Now, for my HTTPService, I can just do:
service.send ( myProjectVO.toXML() ) ;
It’s also really easy to update in case the Rail’s side changes for whatever reason. I usually can just copy from ServiceCapture, paste into the VO class since XML can now be written without quoting rules, and swap the values with bindings to the VO’s public properties… nice!
I don’t apologize for all the things I said, but wouldn’t have been so non-enthused had I known about bindings.
…so… uh… anyone got Remoting working for Rails yet? Or at least a WebService way of using Rails vs. frikin’ HTTPService?