<D <M <Y
Y> M> D>

[Comments] (1) Purchase Order Equivalent: Before I left for India, someone emailed me with a random REST question. Yesterday, they re-sent the email with a kind of rude preface that implied I have some sort of SLA for answering peoples' random REST questions. Which I don't! I'm a private citizen who's free to answer a given email whenever I want, or even to never get around to it—the same right I allow the Internet pseudo-celebrities to whom I send email.

So I was kind of cheesed off at this person, but frankly the rudeness worked—I answered the question just to get them out of my hair. The question is, how do you make the creation of a new resource an idempotent operation? Imagine a factory resource that you POST to to create something new. Typically, if you send the same POST request twice, you'll get two new resources. How do you make it so that the first request creates a new resource and the second request fails?

The short answer is to use POST Once Exactly. I mention POE in the REST book, but POE never made it out of the Internet-Draft stage, and I can't even find the Internet-Draft at Mark Nottingham's site anymore. Besides which, the email message described something similar to POE as an option, but wanted something simpler. So here's something simpler, for some value of "simpler".

When you buy (eg.) computer hardware from NewEgg, they give you a space for a "purchase order" along with shipping address etc. This is for use when you're buying stuff in a commercial context. You can put whatever you want in that space. The purchase order is a key into your company's purchasing system. It's meaningless to NewEgg.

Newegg doesn't use the purchase order for anything, they just put it on the invoice for your convenience. But in theory, they could keep track of the purchase orders you've used. Since they know which orders are yours, when you place a new order the site can run a quick check to see if you've used that purchase order before. If you have, they can stop the purchase from going through, since you're probably trying to process the same purchase request twice.

So the simpler solution is. You're defining the media type or the form describing what the client is supposed to POST to the factory. Include a slot for a "purchase order". This is a random string chosen by the client whose only purpose is to uniquely identify a resource to be created. On the server side, reject a POST request that uses a purchase order already used by this client ("this client" distinguished from other clients by the authentication credentials). Now the POST request is idempotent: sending it 10 times is the same as sending it once.

I call this strategy "Purchase Order Equivalent", or POE. Thoughts?

[Comments] (4) Bully For Torosaurus: While I was gone there was an online flurry of interest about a paper in the Journal of Vertebrate Paleontology, "Torosaurus Marsh, 1891, is Triceratops Marsh, 1889 (Ceratopsidae: Chasmosaurinae): synonymy through ontogeny". The general tenor of this discussion is conveyed by this Daily Mail headline: "Triceratops 'never really existed but was just a young version of another dinosaur'". And the larger implication is conveyed by this guest post to Kottke, classifying Triceratops with Brontosaurus and Pluto as an instance of science cruely taking away a beloved childhood icon.

First off, the Daily Mail headline is inaccurate. (Shocking, I know.) It should be "Torosaurus 'never really existed but was just a mature version of another dinosaur'." Why? Look at the dates. The first Triceratops was discovered in 1899, and Torosaurus was discovered two years later. When two species turn out to be the same, the earlier name takes precedence; that's why Brontosaurus became Apatosaurus and not vice versa. The name of the paper is "Torosaurus is Triceratops", not "Triceratops is Torosaurus". So whatever happens, the name Triceratops stays.

But it is just a name. There's not some platonic form of Triceratops that can be taken away from you. Nothing changed about the universe. Pluto is still out there and these animals did exist. But we come up with abstractions like "planet" and "Triceratops" to help us manage the complexity of the universe, and abstractions are always leaky.

All three of the incidents in that Kottke guest post have this in common: you learned to give a name to something, and then the people responsible for names changed the name on you. Here's a 1989 New York Times editorial quoted by Steven Jay Gould in the title essay of Bully for Brontosaurus:

The Postal Service has taken heavy flak for mislabeling its new 25-cent dinosaur stamp, a drawing of a pair of dinosaurs captioned ''Brontosaurus.'' Furious purists point out that the ''brontosaurus'' is now properly called ''apatosaurus.'' They accuse the stamp's authors of fostering scientific illiteracy, and want the stamps recalled.

Apparently there was backlash against this, even though Brontosaurus was formally retired in 1903, so there's no reason except pop culture that anyone in 2010 (or even 1989) should even remember the name "brontosaurus". And people got really angry about the redefinition of "planet" to exclude Pluto. But if scientists made some discovery that shattered our preconceptions, like discovering that Triceratops was a carnivore or that Pluto is actually the size of Jupiter, no one would be angry. There'd be no one to be angry at.

People get angry when they see the social constructs of science being refactored to be simpler. It looks like the scientists are cheating, because the refactoring has no basis in physical reality. But the constructs themselves—"planet" and "species"—are just tools we came up with to make thinking easier. This is why two species can be discovered to be the same species, and why the name of the combined species is chosen according to arbitrary rules. The rules are all there are.

Incidentally, you know how the Apatosaurus/Brontosaurus thing happened? Well, in 1877 A.O. Marsh described Apatosaurus in a "typically rushed note" (Gould), and then two years later he described Brontosaurus. As I mentioned, the distinction lasted until 1903. Quoting Gould again:

When [Elmer] Riggs restudied Apatosaurus and Brontosaurus, he recognized them as two versions of the same creature, with Apatosaurus as a more juvenile specimen. No big deal; it happens all the time.

That's exactly what happened with Triceratops! A.O. Marsh really loves taking credit for discovering species. He describes some juvenile specimens as Species A, and two years later some more mature specimens as Species B. Still later, some other paleontologists restudy the specimens and call him on it. Same story both times. It's just that in the case of Apatosaurus it took about twenty years, and in the case of Triceratops it took a hundred and thirty.

At the Museum of the Rockies there's a line of Triceratops skulls from juvenile to adult. Jack Horner, one of the authors of this paper, is the paleontology curator at the MotR and probably worked on that exhibit. I wonder if there was some moment where Horner looked at that line of skulls and thought "Maybe that should keep going..."


Unless otherwise noted, all content licensed by Leonard Richardson
under a Creative Commons License.