Featured Post

Applying Email Validation to a JavaFX TextField Using Binding

This example uses the same controller as in a previous post but adds a use case to support email validation.  A Commons Validator object is ...

Sunday, December 19, 2010

Character-based Identifiers

When working with web applications, it's convenient to use an identifier like 'bekwam' or 'compId=101' rather than a full name like "Bekwam, Inc.". The latter contains special characters (spaces, periods, commas) will need to be encoded for handling on the web or for JavaScript processing. As a result, most web applications will use database identifiers to obviate the need for encoding.



An alternative to a numeric identifier (?contactId=332) is a character-based value (?contact=walkerca). The character-based values render nicely on a URL and are convenient working with a database, often eliminating the need for an extra join to produce a meaningful query.

A few guidelines for a character-based value

  1. Limit the string length. 5 or 6 characters will contain sufficient ids, but may require a step to deconflict ids.
  2. Restrict characters. No spaces or special characters that would need to be encoded (and decoded)
  3. Encode a handling type. Preprend an additional character if processing is made easier.
  4. Accept all cases but standardize on one.

For a company like 'Kensington Inns, Inc.', an example algorithm would turn this into KENSIG or HKENSI where the 'H' standards for 'Hotel'.

While numeric identifiers are used throughout relational databases, a well-placed, character-based identifier can make processing easier, URLs simpler, and save an extra join on database queries. A character-based identifier helps troubleshooting, obviating the need to correlate the data to decode an unfamiliar integer.

This post is replicated from http://my.opera.com/walkerca/blog/2010/12/06/creating-identifiers-on-the-fly.

No comments:

Post a Comment