
On Mon, May 24, 2010 at 8:49 PM, Gregory Collins
Andrey Popp <8mayday@gmail.com> writes:
Related to URL routing solutions in Yesod and Snap — I've found the Snap way to be more comfortable, maybe this is because the same syntax is used by Python/Ruby web frameworks (I personally have experience with many Python web frameworks). Also I don't think that URL routing type safety is also very important here.
There is actually nothing stopping us from providing a typesafe URL routing engine; we just haven't done it yet because like you, it isn't very important to us. Some people really like it though, so I can see us providing something eventually.
I'm just curious if anyone's actually *used* type-safe URLs in production web apps. I'm not really aware of an implementation besides what Jeremy Shaw has done (first urlt and then web-routes). I'm afraid that the technique is not getting the credit it deserves.
When I say type-safe URLs, I'm talking about having a datatype which represents all possible routes in an application, a function to convert from that datatype to a String, and a function to attempt converting a String to that datatype. As a simple example: data MyBlog = BlogHome | BlogEntry String | AtomFeed Then, instead of typing something like "/entries/" ++ entryName ++ "/", you just type BlogEntry entryName. In this simple case, it doesn't do much more than ensure you don't make typos. I can't go into details, but I had a project where I needed to change an entity relationship from many-to-many to many-to-one, and suddenly I had to remove an extraneous parameter from all of my routes. Due to type-safe URLs, I changed the datatype and the compiler caught each and every time I needed to modify the code. More simply, if I decide suddenly to rename "/entry/1/" to "/post/1/", I only need to change the URL rendering function and all of my code is updated automatically. This monologue isn't meant as a Yesod-is-better-than-Snap, it's meant to point out that type-safe URLs are a very powerful feature, and I think it fits very nicely with the Haskell nature. I'd really urge people to look hard at them and consider using them. Michael