Tuesday, June 21, 2011

Reuse, Reduce, Recycle...again

Ok fine, it was an intense week folks, the team struggled with a lot of legacy code (arghh) . Anyway, do you remember Up With People, Reuse Reduce Recycle about two posts ago? Good, I'm going to tell you a story:
Let's suppose you want to go to New York City (are you living there? Ok, stop reading this post, go out, jog in central park, eat something at Bubba Gump etc. etc. etc.).
Let's move on, you are not living in NYC, not in Brooklyn, Queens... but far from Manhattan and you are looking for a flight from your hometown to The Big Apple, so you browse some flight search engines.
One more hint: you are not someone who likes to socialize, to chit-chat, to talk about the weather, you are not human you are... a programmer! Are you living in NYC and you are human? Stop reading this post, go out, jog in...
As you are a programmer, you want to know some of the internalities of flights and how data is transferred from server to client. Finally during your adventure as a novice Sherlock you find at 85%... hmm at 91%... hmm at 97.49% an: XML.

When I find an XML, I always think to myself: I could merrily develop with my favorite language (Smalltalk you guess), why should I face with XML, the Bernie Madoff of languages, something that robs semantic from riches (Smalltalk) to put it in the trash?

In this context you can have something like:

<route>
      <flights>
            <flight>
                  <flightNumber>123456</flightNumber>
                  <departure>Milan MXP</departure>
                  <departureTime>10:30 AM 20110101</departureTime>
                  <arrival>New York City JFK</arrival>
                  <arrivalTime>12:30 PM 20110101</arrivalTime>
            </flight>
          .
          .
      </flights>
</route>

That annoying structure is multiplied for thousands of flights and I don't want to mention: fares, meals, taxes, types of airplanes and so on. You can easily imagine how this xml can be cumbersome.
What can be useful is a mechanism to take a root object (Route) on the server, packing it with all its attributes, transferring it on a client and restoring it there. Many languages support this mechanism: it's called serialization, in Smalltalk you can use a special object: SmartRefStream to easily serialize any object tree.
Ok... ok... I can hear your objections: "XML is a serialization format", "XML provides interoperability" I know, but SmartRefStream is there, smiling at you, there is no need to invent another fashionable format if I can use an effective one, we don't need interoperability, we need operability! We want to use and reuse it, we want to reduce the complexity, not to introduce a new format. But you know I'm not human, I'm a programmer, but not a programmer, I'm a smalltalker.
See you folks.