Hacker News new | ask | show | jobs
by RommeDeSerieux 6254 days ago
I don't understand why almost every (except for Django) framework author insists on hiding regular expressions in his routing scheme and instead forcing developers to use his homegrown language with slashes hardcoded. It's not like the developers are afraid of regular expressions, are they? This is so painful, i have to undo the work of those routers sometimes to get the results i want.

Luckily this is Python so it's possible to monkeypatch the implementation.

2 comments

Regular expressions are overkill in most cases, and clutter the code. Do you really always know you need a 6 character long integer in a URL? what you really want is an ID, which may be a 6 character integer. Simple keyword-based routing is fine for 99% of cases.
Here is a simple example which pops up too often: i need a "flatpages" controller which will display a page based on its url. Or, as another example, a category tree. With regexes, this is a piece of cake. With routers that try to hide regexes, i have to undo the work done by the router.
What I don't get is why web frameworks put routing into the code at all. Most of them don't do anything interesting with it (Rails is the most prominent exception), and if you're just gonna map a few things with regexes, well... what's so difficult about mod_rewrite?
Portability between servers and reusable apps are the first examples that came to my mind. A reusable app would need an extra installation step and need to duplicate its routes in more than one syntax for different webservers.