[web-devel] Re: ANNOUNCE: yesod 0.2.0

Michael Snoyman michael at snoyman.com
Mon May 24 15:10:21 EDT 2010


On Mon, May 24, 2010 at 8:49 PM, Gregory Collins <greg at gregorycollins.net>wrote:

> Andrey Popp <8mayday at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/web-devel/attachments/20100524/3a2025d5/attachment.html


More information about the web-devel mailing list