My Querystring Argument Neurosis
I have a serious web development neurosis: I hate querystring arguments. You know the garbage after the page name in a URL? Like this:
I hate them. I think they’re ugly, unwieldy, and expose too much of your application to the world. This is an utterly irrational thing, I know, because querystring arguments work perfectly well. I just need to get over myself.
But is the querystring argument falling out of fashion? A lot of apps now run all requests through a single page, and they grab and parse the URL themselves. For instance:
This would show page 1 of products in the hunting gear category. There is no “products” or “hunting_gear” folder or file named simply “1.” Instead, this URL is mapped to an actual block of code. You can do this with a
RewriteRule pretty easily (you could do it with a PHP auto-prepend file too).
In my PHP apps, I use an
AliasMatch rule to route everything to a single page and I have a mapper like this:
/product/[0-9]+/edit = edit_product.php
This uses a regular expression to map a URL pattern to a file. If the first “directory” is “product,” the second is a number of some kind, and the third is “edit,” then send them to the page to edit a product. That page will grab the number out of the URL and use it to load an object.
J2EE does this too, to map URL strings to servlets. I have no doubt that .NET has the same functionality in there somewhere. I think Rails does this too, from what Joe tells me.
AcceptPathInfo directive for Apache, you can do things like this:
But that just looks sloppy to me. I don’t know why. eZ publish does this by default, and it bugs me to no end.
Finally, today I found this, and it’s what prompted me to write this little diatribe:
So they’re using
AcceptPathInfo, but each “directory stop” along the way is a key-value pair. I like this. It speaks to the aesthetic in me, or to the neurotic, depending on how you look at it.
This last example perhaps proves that it’s just the syntax I don’t like – all those
='s floating around are like fingernails on a blackboard to me. This example is key-value just like traditional querystring arguments, so the function is the same, just the syntax is different. The colon-slash syntax just looks cleaner to me.
Am I the only one with this problem? Does anyone else hate querystring arguments as much as me?