And now, more discussion of DHH's World of Resources ideas...
From what I saw at RailsConf, the reaction to the unveiling of ActiveResource was quite mixed. The two big concerns were, "is CRUD a good fit for my model/controller design?" and "should I use human-readable names for resources, or numeric IDs?". I've seen a fair bit of discussion on various blogs about the former, but none at all on the latter.
Some context: In his by now infamous keynote, DHH said that simple numeric IDs were the best way to name resources in URLs. This is analogous to ActiveRecord's standard of using auto-increment integers for primary keys instead of whatever natural key the data model may imply. For example:
natural: /employees/josh numeric: /employees/13
DHH made the point that naming resources using what is effectively a portion of their contents is not a reliably permanent name. The city of Sunset, Florida changed its name to Sunrise (not surprising, given the local demographics) - should that make all URLs to "/cities/Sunset" invalid?
First off, let me say that if resource URLs are meant for consumption by another program via a RESTful web service, than having human-readable URLs is a non-issue. Machines are totally fine with numbers. However, low-level naming schemes have a tendency to bubble up to where the user can see them. Admit it: you've written at least one app in Rails that used primary keys in the URLs. Don't your users just love seeing their profiles displayed with the friendly URL "/users/show/13"?
I keep running into this issue myself, not only in software design, but even in how I choose permalink names for articles in this blog. It's nice to have a human-readable URL to paste into an email, as it gives a reader an idea of what the referenced article is about, and might make it easier to find a link in a list of bookmarks. But I also worry about the longevity of links, and managing identity equivalence. Bookmark services like del.ico.us don't equate two different URLs to the same page, so http://blog.hasmanythrough.com/articles/2006/06/30/cruddy-searches and http://blog.hasmanythrough.com/articles/read/375 will be counted separately. This may not seem a big deal, but it not only affects the popularity ranking of a page, but also messes with finding areas of overlapping interest with other users. I wonder if the folks at bookmarking services are thinking about this issue; I assume Google is.
So there seem to be three issues to consider for URL names of resources:
- Readability by humans
- Longevity (permanence)
- Identity comparisons
I talked this issue over with a bunch of people at RailsConf, and the tentative consensus that emerged was this: Use numeric IDs for resource permalinks. Allow human-readable (or actually, human-writable) URLs as an alias or heuristic search for an entity, but do a permanent redirect (301) to the numeric permalink once the entity was found.
Looks good on paper, but I want to do some usability testing to see how it flies.