May 04 2009

On named parameters

Category: IdeasAleksander Kmetec @ 5:07 am

Here’s a proof that quitting your job and not working on anything for two months is not good for you: I just spent two days pondering why named function parameters are loved by coders and considered an important part of many programming languages while named parameters in URLs are considered to be ugly, harmful and one of the leading causes of scurvy. Developers will even find a way to emulate named function parameters in languages which don’t support them by default while at the same time they will try their best to make all the parameters in URLs of their websites strictly positional. It makes everyone look a bit confused and bipolar, if you ask me.

Here’s a quick overview of the situation.

Named parameters in URLs: BAD
http://domain.com/list?type=fruit&page=1&items=20

Positional parameters in URLs: GOOD
http://domain.com/list/fruit/1/20

Named parameters in function calls: GOOD
foo.list(:type => “fruit”, :page => 1, :items => 20)

Why is this so? It might have more than just a little bit to do with the fact that coders spend a lot of their time reading, writing and modifying function calls, while URLs are only rarely modified by anyone (or even read, for that matter). The need to modify URLs is so rare in fact that many security holes exist only because developers never even remotely considered that someone might insert an unfriendly value into one of the parameters. It makes sense then that if URLs are only meant to be looked at, to make them short and pretty and clean of any characters which make them appear as if they’ve been involved in an explosion at the ASCII factory.

Why then is the URL, this unfriendly sequence of characters, still presented as a fully editable value? Is it really not possible to turn it into anything more than a barely readable “you are here” sign?

Microsoft managed to do something interesting with the way directory paths (URL’s distant relatives) are displayed in Vista and Windows 7: each directory is a separate button and clicking any one of them takes you directly to that directory.

Windows explorer in Vista

Two different ways of displaying the same directory path

Couldn’t something similar be done for URLs? Here’s my suggestion: make it easy to experiment with different parameter values. Hide all the “noise” characters. Turn each key/value pair into a button and offer alternative values when somebody clicks them.

Location bar

Now, this might not catch on with your average Joe Streetperson, but it does look like it could be useful to developers when they are testing a website or a web service which returns different XML/JSON based on parameter values.

Think of it as Intellisense for the location bar.

Spread the word!
  • HackerNews
  • Twitter
  • Facebook
  • del.icio.us
  • StumbleUpon
  • DZone
  • Reddit
  • Digg

No related posts.

Tags: , , ,

Leave a Reply