What Mark (or Kevin or Gigi) said in their book was this:

"What makes raise redirect nice is that it's an unambiguous signal
that the code that follows is not going to execute.  After you've
stated you want to redirect the user, further processing doesn't make
sense.  If redirect was a normal function call, it would be possible
to call it and then proceed to produce output that you expect to go to
the browser, which is confusing.  raise redirect neatly eliminates the
possibility."

While I was initially of the mind that it looked clunky, the elegance
of the meaning conveyed with it is inarguable, and I have worked the
same mechanic into some of my own projects since then.  It's clear
that processing will not continue past that point.  Now sure, it's
just about the only call we use in TG that works this way (at least,
to which I have been exposed thus far), but I still think it's a
compelling argument.


Mike


On Aug 13, 3:59 am, Jorge Vargas <[email protected]> wrote:
> On Wed, Aug 12, 2009 at 6:53 PM, Carlos Ribeiro<[email protected]> wrote:
> > My 0.02 cents - not that anyone asked :-)
>
> > I agree that "redirect()" looks cleaner, but I personally dislike magic
> > exceptions happening at my back. It's not clear why does it break the
> > execution flow. Using "raise" does not look as fancy but seems to me to be
> > the "the right thing to do".
>
> That's a valid point. But who says redirect is an exception in the
> first place? I mean it is implemented as an exception but it really is
> a method call to another controller. So yea it's a matter of tastes.
> On that same camp using redirect() opens the possibility for a future
> implementation that is not an Exception :)
>
> > But that's just my opinion.
>
> > Carlos Ribeiro
>
> > On Wed, Aug 12, 2009 at 03:35, Jorge Vargas <[email protected]> wrote:
>
> >> On Wed, Aug 5, 2009 at 12:20 AM, El Tea<[email protected]> wrote:
>
> >> > In TG1, the only redirects I ever saw were handled as exceptions.  In
> >> > TG2 I've seen two forms:
>
> >> > redirect('/somewhere')
>
> >> > raise tg.redirect('/somewhere')
>
> >> > Is there a "right" time to do one vs. the other?  Is one more correct
> >> > than the other?  One thought I've had is that the raise may be used if
> >> > you want to indicate that any database transactions from that request
> >> > should be discarded (I think this is done on exceptions).
>
> >> both are ok.
>
> >> The second one was to keep compatibility with TG1, I use
> >> redirect('foo') as it is shorter (in the back it's doing the exception
> >> thing)
>
> >> > Thoughts?
>
> > --
> > Carlos Ribeiro
> > Consultoria em Projetos
> > blog:http://rascunhosrotos.blogspot.com
> > blog:http://pythonnotes.blogspot.com
> > mail: [email protected]
> > mail: [email protected]
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to