defnull/bottle — pull request #518 by nicolas-van (2013-06-25 19:22:11+00:00)
Title: Route ordering similar to werkzeug

Since you merged my last pull request, whose main purpose was to ease implementation of route ordering based on any priority algorithm, I propose a sorting algorithm based on werkzeug's one.

The precise algorithm used by werkzeug is hard to find. But it still has some documentation in the code, in werkzeug.routing.Route.match_compare_key.

The ordering is the following:
- static routes always have top priority (that was already the case in bottle)
- for dynamic routes, the more complex it is the more priority it has
- for routes with the same complexity, it compares the different parts in the route from left to right. Static parts always have an higher priority. The only difference with werkzeug is that, in werkzeug, some type of dynamic patterns have more priority than others (ie: integer has more than path), but I didn't think it was really necessary to implement that.

Even if you don't like the idea to switch to an auto-ordering mode for routes, I think it would still be a good idea to implement it as an option in the Router class.