(Skip to main content.)

Blogs Quoderat Land and Hold Short

Quoderat

Archive for May, 2006

Firefox vs. PRG

Wednesday, May 31st, 2006

[Update: it's working now, after upgrading Ubuntu. Here's an online test for your own browser.]

Post/Redirect/Get (PRG) is a common web-application design pattern, where a server responds to an HTTP POST request not by generating HTML immediately, but by redirecting the browser to GET a different page. At the cost of an extra request, PRG allows users safely to bookmark, reload, etc.

When someone attempts to reload a page generated by a POST request, browsers will generally pop up a warning that reloading will cause a form to be resubmitted, possibly causing you to purchase two sports cars (etc.) — that warning is a good thing. Strangely, however, Firefox 1.5.03 will pop up the same warning after a PRG operation, when reloading should not cause anything bad to happen. I can think of a few possible reasons:

  1. Firefox wants to repeat the entire PRG operation rather than just the final GET
  2. Because the GET was the (indirect) result of a POST operation, Firefox still wants to warn you that there might be something fishy.
  3. An obscure bug.

I’m leaning towards #3, but I’m curious about whether anything thinks that Firefox is doing the right thing here, and whether other browsers (MSIE, Opera, Safari, etc.) act the same way.

Continuations, cont’d

Saturday, May 20th, 2006

[Update: see further contributions to the discussion from Ian Griffiths, Avi Bryant, James Robertson, and Joe Duffy; note also John Cowan's excellent comment below, pointing out that hidden fields work with the back button but not with bookmarks.]

It looks like continuations are back on the discussion board (Gilad Bracha, Tim Bray, and Don Box). I spent some time with Scheme a decade ago and continuations were one of the new features I had to try to understand. Then, as now, I found them more clever than practical.

Gilad sets up a use case for continuations before he goes on to oppose them: in essence, a web application could use continuations to maintain separate stacks, so that as a user hits the back button and then starts down new paths, the web application would not become confused, selling the user a trip to Hawaii instead of Alaska. I can see how continuations would work for that, just as I can see how a bulldozer could turn over the sod in my garden, but I’m far from convinced that either is the right tool for what is really a much simpler problem.

Explicit state

First, a continuation preserves the entire state of a program, including the stack, instruction counter, local variables, etc. How much of that do you really need for a hypothetical travel web app? In reality, you probably need, maybe, 1-5 variable values to restore a previous state in the travel app, so why not just save those explicitly? It would be faster, more secure (less information being saved), and much easier to performance tune and debug (since no magic is happening behind the scenes). Save those variables in a database, in a hash table, in an XML or CSV file, in memcached, or wherever happens to be most convenient. You may be looking at under 100 bytes for each saved state, so if you really want to do this, it’s not going to hurt too badly.

REST

But do you really want to do this? Most of the discussion around REST has focussed on the use of persistent URLs and how to use HTTP verbs like GET, POST, PUT, and DELETE, but there’s another, perhaps more critical idea behind REST — that the resource your retrieve (a web page, XML document, or what-have-you) contains its own transition information.

Let’s say that you load a web page into your browser, load more web pages, then use the back button to return to the original one. Now, select a link. What happens? Did you browser have to go back to the original web server, which was using continuations (or other kinds of saved state) to keep track of the links from every page you visited, so that it won’t send you to the wrong one? Of course not. The web page that you originally downloaded already included a list of all its transitions (links), and intuitive things just happen naturally when you hit the back button.

The web is stateless, but web application toolkits maintain pseudo-sessions (using cookies, URL rewriting, or what-have-you) that makes them look stateful, and that makes programmers lazy. Obviously, you don’t want to stick information like ‘isauthenticated’ on a web page, since it could be forged; likewise, you don’t want to put a credit-card number there. But it is trivially simple to make sure that forms, like links, go to the right place even when you hit the back button — just make the transitions fully independent of any session stored on the server side. For example, consider this:

<form method="post" action="/actions/book-trip">
  <button>Book this trip!</button>
</form>

Presumably, the trip the person was looking at is stored somewhere in a session variable on the browser. DON’T DO THIS! As Gilad pointed out, someone hitting the back button might end up booking the wrong trip. There are gazillions of ways to push all of the context-sensitive stuff into the web page itself, where it belongs. Here’s one example:

<form method="post" action="/actions/book-trip">
  <label>Book your economy trip to Alaska!</label>
  <input type="hidden" name="destination" value="alaska"/>
  <input type="hidden" name="package" value="economy"/>
  <button>Book it.</button>
</form>

Here’s another:

<form method="post" action="/actions/book-trip/alaska/economy">
  <label>Book your economy trip to Alaska!</label>
  <button>Book it.</button>
</form>

This is 100% backbutton-proof and it’s trivially simple to implement. It took me a while after reading Gilad’s (admittedly, strawman) example to realize that there are people who do not develop webapps this way. If they do this much damage just with a Session stack, how much pain will they be able to cause with continuations?

The REST people are right, at least on this point: there’s no need to drive a continuation bulldozer through your webapp, when a little REST garden spade will work quite nicely (and won’t tear up your lawn in the process). Don suggests that there may be other, more legitimate use cases for continuations outside of web applications, and I have no reason to disagree, but I would like to look at them pretty carefully.

National Debt(s)

Saturday, May 20th, 2006

Tony Coates is celebrating the elimination of the Australian federal government’s net debt. During the 1970s and 1980s, Canada carried a brutal public debt, to the point that our federal government was spending more on interest than on any major government program (healthcare, defence, education — you name it). I suspect that Australia was in a similar situation. It’s a vicious circle, where the government ends up spending more and more but delivering less and less.

The ratio between public debt and GDP in a rich country shows how capable that country is of dealing with its debt; less directly, it also shows how fond that country is of big government (though high debt can also simply indicate undertaxation). With that in mind, the following table destroys a lot of the stereotypes about how well different governments manage their finances and how fond they are of big government:

Country Public debt:GDP ratio
Australia 16.2%
New Zealand 21.4%
Canada 38.7%
U.K. 42.2%
Spain 48.5%
Sweden 50.3%
U.S. 64.7%
France 66.5%
Germany 68.1%
Italy 107.3%
Japan 170%

(Source: CIA World Factbook; all figures for 2005.)

Anti-big-government U.S.? Impoverished Spain? Debt-ridden U.K.? Soviet-Canukistan? Forget it. On the other hand, however much Americans may complain about financial mismanagement under their current administration, things could have been worse — at least they didn’t have to deal with five years of Silvio Berlusconi.

Announcement: XML 2006 RSS news feed

Wednesday, May 17th, 2006

The XML 2006 conference (Boston, December 5-7) has a low-traffic RSS news feed for major announcements. In your weblog reader, subscribe to the following RSS 2.0 feed to stay up to date on deadlines, dates, and other important information:

http://2006.xmlconference.org/news.xml

If you prefer to read an HTML page, the same information is available as a formatted web page (autogenerated from the RSS).

XML 2006 Call for Participation

Wednesday, May 17th, 2006

I’ve just come back from announcing the XML 2006 Call for Participation at the XTech 2006 conference in Amsterdam (I had the privilege of following two excellent opening keynotes, Paul Graham from Y Combinator and Jeffrey McManus from Yahoo, ensuring a good crowd).

From now until Monday 19 June, we are accepting presentation and tutorial proposals for the XML 2006 conference in Boston (5-7 December; tutorials 4 December). This year, we have four focussed presentation tracks, and we’re eager to see your submissions. You can read the full call for participation online at

http://2006.xmlconference.org/call-for-participation.html

Please spread the word on other mailing lists or discussion groups. Thanks.

Getting the point of Skype and chat

Tuesday, May 16th, 2006

I signed up for Skype a while ago, put EUR 10 into my account, and made a few calls. It was cute, it worked, but after a couple of experiments I couldn’t see the big deal. After all, Skype lags by a second or two (like the old trans-Atlantic cables), it has poor sound quality even compared to my cell phone, and phone calls in North America, even long distance, are so close to free that Skype hardly matters.

Over here in the Amsterdam this week, it’s a different story. My North American cell phone doesn’t work (of course), calling from the hotel is ridiculously expensive (even calling a toll-free number), and there are very few public phones. All I need is a wireless Internet signal, though, and I can call home on Skype to my heart’s content for (literally) pennies. Even more importantly, I can call North American toll-free numbers directly, something that’s not otherwise possible at any cost from Europe. OK, now I get the excitement around VoIP.

Instant messaging (aka chat) has been around in various guises a lot longer than Skype, but I’m in my fourties, and thus, a little too old ever to have used it socially. What finally changed that is Google’s integration of IM right into their webmail service. While I’m reading my GMail, a little green light goes on when anyone I know is reading at the same time (the joys of AJAX). After midnight Amsterdam time last night, I ended up with three chat windows open — one for my spouse, and one for each of my kids — carrying on three separate private conversations about how their days had gone. I could have called on Skype, of course, but I couldn’t have talked privately to all three at once, and I wouldn’t have known when they were all free without those little green lights. While typing furiously and switching among windows, I got perhaps a tiny taste of what it’s like to be a hyperactive 16-year-old girl.

XTech, AJAX, and Rails

Speaking of AJAX, IDEAlliance staff has told me that the AJAX developer’s day here at XTech 2006 has been so popular that it’s almost overwhelmed, with a huge number of last-minute walk-ins. The Rails tutorials have also been popular. There’s obviously a lot of demand for AJAX and Rails information over here — good job, Edd.

Now, back to age-appropriate communications. When’s the penknife to sharpen my quill? …

Giving thanks

Monday, May 15th, 2006

Over on XML.com, David Peterson gives Microsoft some well-deserved thanks for implementing and popularizing the XMLHttpRequest object that’s so useful in modern web development. He also thanks them for not charging for it, but of course, if they had tried to charge it never would have become popular (from SAX, I know that paradox well).

Omissions

There are a couple of problems with giving thanks to inventors, though. The first is that you inevitably leave people out. David, for example, thanked Microsoft for all of AJAX and modern web development in general. AJAX doesn’t consist solely of XMLHttpRequest, however; it also needs JavaScript and a DOM (both pioneered by Netscape) to manipulate the client display, and something like XML (W3C) or JSON (Douglas Crockford) to encode the messages. Most modern web developers also want CSS (HÃ¥kon Wium Lie and Bert Bos). And then, of course, there’s HTML and HTTP (Tim Berners-Lee). To illustrate my point, I’ve certainly left out a lot more that I could have included here, and have likely misassigned at least some credit.

Death of the inventor

The second problem is that it almost never makes sense to assign credit to individual people or companies. Who should get credit for SAX? Me, because I coordinated it? James Clark, because I based many of the ideas on his earlier SGML interfaces (and he suggested many of SAX’s features)? Tim Bray, because he thought up a catchy name? The other dozens of other xml-dev members who contributed most of the core ideas? The major software vendors who actually decided to use SAX, giving it credibility outside of the xml-dev community?

The same applies to just about every other technology we use. Not only do they depend on other innovations (the Web without TCP/IP? SAX without XML?), but the successful innovations are almost always simple and obvious, so their main value comes not from any particular technical brilliance but from the brute-force fact that lots of people use them — in other words, community-building is more important than innovation. Microsoft imitated Netscape’s level-0 DOM, and then the W3C standardized it so that it would work across browsers, then browser developers agreed to follow along, then web developers decided it was safe to start using it. Microsoft initially failed to build a community for XMLHttpRequest (which was a proprietary ActiveX component), so it languished mostly unused for years, until other browsers like Mozilla/Firefox, Safari, and Opera decided to support it as well — it was only then that we started to see a real community grow, and high-profile sites like Gmail and Google Maps take off. Tim Berners-Lee’s original HTML would hardly have mattered if the early Mosaic browser hadn’t shown how to make it user-friendly. Etc., etc. While Netscape introduced some good ideas like the DOM and Javascript, they also introduced some that flopped (does anyone else remember CORBA in the browser?) — no community of users, no success.

Thank the users

The moral of the story is that technology success is not something that a person or company gives to the net, but something that comes back from it, as if you threw a stone at a tree without knowing whether an avalanche of silver or of bird dung would shower down from the branches onto your head. A complex, brilliant idea with no users is worthless; a simple, mediocre idea with lots of users is a treasure.

Mobile Web at XTech

Wednesday, May 10th, 2006

Michael Smith has a short post about the Mobile Web Morning at XTech 2006 next week in Amsterdam. I’ve been excited about the mobile web for a long time — granted, it’s been slow taking off, but with mobile phones as the only form of connectivity (voice or network) for much of the developing world, I think that it’s bound to become hugely important. I’ll be charing the first session on Friday morning, and hope to see many of you there.

How many environments?

Tuesday, May 2nd, 2006

Assume that you are a lone developer, maintaining a small web site in a shared hosting account. How many software environments do you need from development to production?

One environment

On the simplest level, you could develop directly in your ISP account, loading and saving files remotely via SFTP, WebDav, etc. — in other words, your development and production environment would be the same. For anything non-trivial, that’s a pretty hairy way to work, since you have no way to test changes before they’re rolled out into the world.

Two environments

I normally use the two-environment approach that (I suspect) is the most common one for single-developer LAMP sites: I maintain a development environment on my notebook, and periodically upload changes to the production environment at the ISP. I try to run roughly the same version of Apache, PHP, MySQL, etc. as my ISP, but otherwise, I take no special steps to replicate the production environment. On my notebook, I set up the development directory as its own virtual host (e.g. http://localhost:8001/, etc.) so that I can test changes literally as I type.

Three environments?

Even though there are no other developers working with me right now, I sometimes wonder if it would make sense to start using a third environment between development and production (a separate directory and virtual host on my notebook). A third development would allow me to run major experiments and restructuring in the development code, while still making small bug fixes, typo corrections, etc. in the stable code before uploading them to my ISP production environment.

While this sounds like a good idea initially, there is a major coordination problem involved in backporting fixes from the middle environment to the development environment, and the middle environment will still become unstable while new changes are rolled out into it, tempting me to create another environment — complexity is, sadly, highly contagious. Have any other lone developers had success (or failure) with this approach?

More

Big organizations use an enormous number of environments to build and roll-out a system:

  • Each developer’s desktop, where code generally lives for a few hours.
  • The development server, typically a single server running database, application server, etc. as well as version control unit/regression tests.
  • One or more test environments, covering integration testing, system testing, user-acceptance testing, etc. (these can range from single servers to small clusters to near-duplicates of the full production environment).
  • The staging environment, which is typically very similar or identical to the production environment.
  • The production environment, where the system runs.

I’m still undecided about whether enterprises help or hurt themselves by making things so complicated — coordinating a lot of people on a big system is hard, it’s even harder to imagine an agile process functioning under so many layers of pain.