Alan Dean

CTO, Developer, Agile Practitioner

Photograph of Alan Dean

Sunday, January 18, 2009

Open Space Code website goes live

Nothing very exciting, to be sure, but the first Coding Day is now up on http://openspacecode.com/

Video of REST at DDD7

In November, I gave my “Separating REST Facts from Fallacies” presentation at DDD7 and I now have the video. Please be aware that the flash stream is 178MB, so please be a little patient whilst it downloads:

The embedded video works fine in both Firefox and Chrome but my IE7 isn’t playing ball, so there is also a WMV version (290MB) available for download.

Saturday, January 17, 2009

HTTP i18N Patterns

I have been dealing with the problems of internationalization (i18N) in order to make applications world-ready for over a decade now. In fact, many years ago, my first community presentation was “Internationalisation and Globalisation in Visual Basic 6”.

There has recently been a discussion on the [rest-discuss] list titled “Conneg for language selection: Just Say No”. I wrote a lengthy response on the thread and thought that there was value converting that into a blog entry.

Don’t confuse translation with localization

Translation is the conversion of source text in one language to target text in another language.

Localization (l10N), whilst typically involving translation, is the process of cultural adaptation.

Imagine that you are book publisher responsible for publishing a work of Leo Tolstoy. In Russia, you would not translate the text (the original being written in Russian). But you would still localize by, for example, putting a price on the cover in roubles. You might then order a translation to French and the imprint would be localized by having a price in euros. Depending on your marketing, the localization may also involve changing the jacket image and will certainly require the book title to be translated as well. However, it seems that there is a section of the market for Tolstoy in France that reads in Russian. In which case, you may decide to have an additional imprint that has no translation but still requires localisation of both jacket image and prices.

Resource translation creates a new resource, translation of decoration creates alternate representations

In REST, it important to distinguish between different resources and different representations. When using HTTP, you can content negotiate (conneg) between alternate representations, but you should not do so between different resources. Instead, you should provide the user with links to follow to view the different resources.

Content negotiation by language or Request-IP address?

Localization conneg can be either language-driven from the Accept-Language HTTP header and/or country-driven from the Request-IP address. Both are valid localizations and both can be used in concert. For example, the price of goods and services are country-specific localizations rather then language-specific (both in terms of the currency used and the tax regime to be applied).

Health warning: URI structure is orthogonal to REST

Before I go into more detail with my examples, I want to make it clear that what URIs look like is, prima facie, unimportant to REST. This is sometimes referred to as URI opacity or opaqueness. Nonetheless, there are good patterns we can employ for URI structure and human-readable URIs are considered to be ‘a good thing’.

Example: Tolstoy on the Web

Carrying on with the Tolstoy example, here is how I would personally approach the structure and content negotiation of his book “Anna Karenina

1. Expose the ‘concept of’ a book called “Anna Karenina” by Leo Tolstoy

http://www.example.com/book/leo-tolstoy/anna-karenina

In this example, I have used the English translations of both names but any language would be acceptable. It is worth noting, however, that regardless of how much we may dislike the fact, American English is the de facto default language of the Web. I would argue that you need a good reason to depart from American English for ‘canonical’ URIs. This is not to say that you cannot have localized URIs as well. In the example below, you can see “book” being translated into “livre” on the URI.

Content negotiate based upon Accept (for media types) and Accept-Language to a list of the various translations of Anna Karenina using the following URI structure:

{canonical-baseURI}.{language-token}.{media-type-token}

A table of example content negotiation URIs from the canonical URI.
URI Language Media Type
http://www.example.com/book/leo-tolstoy/anna-karenina No representation
http://www.example.com/book/leo-tolstoy/anna-karenina.en.html Generic English HTML
http://www.example.com/livre/leo-tolstoy/anna-karenina.fr.html Generic French HTML
http://www.example.com/livre/leo-tolstoy/anna-karenina.fr-fr.html French, as spoken in France HTML
http://www.example.com/livre/leo-tolstoy/anna-karenina.fr-ca.html French, as spoken in Canada HTML
http://www.example.com/book/leo-tolstoy/anna-karenina.en.atom Generic English Atom
http://www.example.com/livre/leo-tolstoy/anna-karenina.fr.atom Generic French Atom
http://www.example.com/livre/leo-tolstoy/anna-karenina.fr-fr.atom French, as spoken in France Atom
http://www.example.com/livre/leo-tolstoy/anna-karenina.fr-ca.atom French, as spoken in Canada Atom

Each of these pages should contain a list of links of the available translations and the countries in which they are available for purchase.

2. Expose the country-specific links for product purchase

There are a number of different ways of hosting country specific URIs:

  • Country Code TLDs (ccTLD).
    For example, http://www.example.co.uk or http://www.example.fr
  • Country-specific subdomains.
    For example, http://uk.example.com or http://fr.example.com
  • Country-specific paths.
    For example, http://www.example.com/uk/ or http://www.example.com/fr/

For my example purposes, I will simply use ccTLDs. If we look at the way in which we have set up our content negotiation for the canonical example above, we see that we can use the same pattern. In many cases, language negotiation isn’t provided for ccTLD domains unless there are multiple official languages. So for http://www.example.fr there might only be localization to French but for http://www.example.ca there would likely be localization to both English and French:

A table of example content negotiation URIs from the ccTLD URI.
URI Language Media Type
http://www.example.ca/book/leo-tolstoy/anna-karenina No representation
http://www.example.ca/book/leo-tolstoy/anna-karenina.en-ca.html English, as spoken in Canada HTML
http://www.example.ca/livre/leo-tolstoy/anna-karenina.fr-ca.html French, as spoken in Canada HTML
http://www.example.ca/book/leo-tolstoy/anna-karenina.en-ca.atom English, as spoken in Canada Atom
http://www.example.ca/livre/leo-tolstoy/anna-karenina.fr-ca.atom French, as spoken in Canada Atom

In some cases, such as Google, the canonical URI step is skipped by sniffing the Request-IP address and then redirecting straight to the ccTLD. Google has the good manners to also provide a link back to the .com domain when it does this.

Friday, January 16, 2009

DDD Belfast

The Call for Speakers has been put out for DDD Belfast on April 4th.

I have submitted a double session on REST. The first session is a reprise of the session I gave at DDD7 and the second session is a new presentation about Azure:

Part 1 "REST: Separating Facts from Fallacies" (1 hour)
Still not sure what REST is or why it might be important to you? REST (Representational State Transfer) is still a deeply misunderstood architectural style. This presentation is designed to dispel some of the myths surrounding REST.
Part 2 "Delivering RESTful systems with Azure" (1 hour)
The new Windows Azure platform allows .NET developers to deliver a variety of cloud-based systems. In particular, Microsoft provides support for REST (Representation State Transfer) style architectures. This session will provide a tour around the key enabling features of the platform allowing highly scalable systems by leveraging the benefits of REST - identifying patterns for success and warning of anti-patterns.

Saturday, January 10, 2009

The Android Phone

My Christmas present to myself this year was a Android developer phone and it arrived earlier this week. Previously, I was using the Nokia N95 which I liked a great deal but it was time to upgrade. What phone to choose though? I could have followed the well-trodden route and buy an iPhone. Certainly, the iPhone seems very nice. At the PDC I watched others using the iPhone around me and I was impressed by the ease-of-use, so it was a strong option. However, it would mean changing my phone provider to O2, who have exclusivity for the UK and I left O2 a while back because of the poor reception quality I was getting. What is more, I couldn’t help but feel that was rather me-too and I am not really that much of a fan of Apple.

So the Android G1 seemed like it was worth a try-out. The developer phone is totally unlocked, although a little pricey at $520 including tax and shipping, so I don’t need to leave Orange to use the new phone. You also need to be registered as a developer on the Android Market to be able to buy the phone, which costs $25 (presumably to discourage timewasters).

You will need to buy a US to UK Plug Adapter to charge the phone from the mains. You can also charge it from a PC or laptop via the USB cable which is important because the phone burns through battery life fast when in use. I estimate that it has a standby battery life of about 24 hours but only about 2 to 3 hours of active use.

The phone does not come with a manual, or at least mine didn’t.

When you first power-up the phone, you need to configure the APN for your operator. There is a note in the box which tells you to visit Quick IM for instructions on how to do this. I found the whole thing very confusing. Turns out, to set it up for Orange, all you need to do is type "orangeinternet" into the APN textbox. I wasted a lot of time figuring out that simple thing out. Also, don’t be fooled by the GPRS in the page title – there is just one setting for GPRS, 3G and 3G+ (the phone negotiates to the highest available connectivity type).

After setting up the connectivity, you are next required to either sign in to an existing Google Account or set up a new one. So far as I know, there is no way to run the phone without a Google Account.

Even better, you can use your Google Apps for Domain account. This is perfect for me as I have set up all my email accounts and calendars to forward or synchronize onto my Google App Domain, so that I have a single place to go.

I have been very impressed with the seamlessness of the integration between the Google account and the Android. All of your Gmail contacts are synchronized across. The phone is very tolerant of the formatting you use for phone numbers and if your contact has an address, the phone contacts allows you to go straight to the integrated Google Maps application to view the address location.

The email interface is clean and easy to use. Touch really works well for scrolling through lists and items. Unlike the iPhone, the Android G1 screen flips out to expose a keyboard:

Not all of the Google stable of applications have integrated applications. Google Docs and Google Reader have to be accessed via the browser, but have nice clean interfaces which I assume are similar to the iPhone versions.

Thought has clearly been given to the nature of intermittent connectivity when mobile. The integrated apps such as Contacts and Mail synchronize so you can work offline and the browser versions are tolerant of connection dropouts. For example Google Reader will gracefully retry without intervention until a new connection is established. This is very unlike Reader on the N95 browser which spits out errors when the connection drops out.

The phone desktop has three panes which you can flick between. The right-hand one has a search entry form which has an intelligent dropdown, which often saves you typing everything completely and also fixes up your spelling when you make a mistake on the keyboard (a feature I like a lot).

All-in-all, I think that this is a wonderful phone that I am very glad to have bought. Better battery life would be nice. You can replace the battery, which allows you to carry a spare, but the procedure for doing that is rather fiddly (unlike the Nokia 95, which makes swapping a battery very easy indeed). The level of usability is on an entirely higher level than any other phone I have used and is good enough for me to productively use the time on the train into work to clear down my email backlog from overnight, catch up on Reader and so on. It will see heavy use from me!