Tuesday, February 21, 2006

Maybe Ours is The Language of The Future

When I explain to people what a web service is and does I try and explain it as the difference between what a human can do with the internet and what a computer program can do with the internet. It goes like this: if you're a human, and you want information about a book, you go to Amazon.com and search for the title or the author in the little search bar at the top, and it leads you to the page with the book on it. You do this because Amazon is a great bibliographic reference, by virtue of the fact that they sell just about every book that exists. If, on the other hand, you're a computer program, and are trying to assemble a library database for somebody, you're a little hamstrung. Even with an internet connection, you don't know how to use a web browser, and programming you to understand how to use the search bar and enter search terms and then read the page that came up--things that come (relatively) naturally to a human being--would take forever. Enter the web service: it provides you with an interface across the internet to, e.g., all of the book information at Amazon, in a way that a computer program can easily access and translate.

Web services, as you might expect, had to come up with a common language that everybody spoke (they also should have come up with a common protocol, like http, but in fact there are at least four that I know of, a few essentially open-source ones, and SOAP, which was developed by...wait for it...Microsoft). What they (where "they" = "The W3 Consortium") came up with is the WSDL. A WSDL (we pronounce that 'WIZ-dul' because that's just how high is our level of dork) is an XML document, because XML is apparently the wave of the future. The WSDL for the web service I described above is here.
Here's a little chunk of it:

<xs:element name="Items">
<xs:complexType>
<xs:sequence>
<xs:element ref="tns:Request" minOccurs="0"/>
<xs:element ref="tns:CorrectedQuery" minOccurs="0"/>
<xs:element name="TotalResults" type="xs:nonNegativeInteger"
minOccurs="0"/>
<xs:element name="TotalPages" type="xs:nonNegativeInteger"
minOccurs="0"/>
<xs:element ref="tns:SearchResultsMap" minOccurs="0"/>
<xs:element ref="tns:Item" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="tns:SearchBinSets" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>


This is the data type of some information that would come back from a search request. You, as a human being, probably look at this and think a) it looks like HTML code (or XML code, if you're riding the wave of the future), and b) it's pretty much gibberish. Which is ironic, because a WSDL is primarily language for humans.

It's language for computers, too, obviously--there are parsers in most programming languages that can read in a WSDL document and produce code libraries to use so that you can call the web service. But that hasn't turned out to be the primary function of the WSDL; the primary function of the WSDL is for me, the human writing the computer program that uses the web service, to understand what the web service does and how it does it. If you speak Wiz-dul, you can look at tags and symbols in this document and understand amidst the gibberish that if you send a request to the webservice and name it, "ItemSearch," and include with it labeled information about the author, artist, composer, or conductor of the item you're searching for (e.g. "Artist='U2'" or "Author='Italo Calvino'") that the service on the other side will understand you and respond in kind with a labelled list of albums or books. You don't need any other documentation than that one page of nicely indented tags.

I'm sure it wasn't the original intent of the WSDL to enable computer programmers to talk to each other about the services they offer; it's become an accidental solution to the nearly intractable problem of creating understandable technical documents about computer code. You've probably never had to read a document from a technical writer that uses English to try and describe what computer code does. You have lived a happier life never having had to do this. You have lived a much, much happier life never having had to write such a document. I don't know if this is a sign of things to come, but XML might turn out to be a model that solves this problem of language quite nicely.

Next: Somewhat more frequent posts!
Tags: , ,

2 comments:

Dan said...

I'm not one of your more mathmatically-inclined/programmer commenters, so pardon the simplicity of my comment, but this was actually helpful because I've never gotten my head around what exactly XML is. Everything I read details how it started, I guess from the same ancestors as HTML, but that you can create your own tags and thus structure a document for a very specific purpose. But I never understood how anyone or anything can render your made-up tags. Isn't RSS XML? Why does that work?

I guess I still don't get it, but you speak to that a bit when you say "there are parsers in most programming languages that can read in a WSDL document and produce code libraries to use so that you can call the web service." In an XML document then, does one create a language and then as long as everyone who talks in relation to that document plays by the same made-up rules of that language, things can happen? I don't mean XML structure rules, I mean parsing the "language" of the tags themselves. Like <balloon><panty><chocolate type="cindy" /></panty></balloon>. Yay, my first XML document!

Fine, I'm not a programmer. I'm going to go write a poem or something.

fronesis said...

OK, so I've read this post a couple of times, and each time I feel two things at the same time: 1) that it's saying something really important that I want/can speak to, and 2) that I just don't quite get it.

I'm not sure what I don't get, but maybe it is, like Dan, XML. I think I fully understand html, because it's a language that's linked to a protocol. When I type http:// into my browser window, then I'm telling that app to use the http protocol to go look for documents written in the html language.

But xml seems to be everywhere, and that doens't make sense to me. As Dan says, RSS feeds are xml. But OpenOffice documents are in xml, and Apple's new word processor pages has xml at its core.

So is xml like a grammer or something? Each app makes up its own language rules, but they follow some rules that are 'xml'.

Where are we now?