On Dec 3, 9:06 am, Gregory Seidman <gsslist+r... / anthropohedron.net>
wrote:
> On Mon, Dec 03, 2007 at 02:54:32PM +0900, Charles Oliver Nutter wrote:
> > Today I was thinking about retry support in JRuby, and figured we've
> > reached a decision point.
> [...]
> > The problem I've run into is that it's really cumbersome to implement this
> > correctly in the compiler, cumbersome enough I'm debating whether we'll
> > support it. There's a few reasons for this:
>
> > - retry is handled using exception; so every method call that takes a block
> > would have to be wrapped with exception-handling for retry to work.
> > Exception-handling is expensive, even if no exceptions are actually raised.
> > It would also add a significant amount of code.
> > - there's no way to know that a method will be reevaluated by looking at
> > it, which makes it both dangerous and impossible to predict.
> > - nobody understands retry, and nobody uses it.
>
> Okay, I disagree with that last point. Retry is very handy when
> appropriate, and I have, indeed, used it.
>
> > As I understand it, retry in a method body is going away in 1.9, so it
> > should be considered deprecated behavior. So far, retry in a block is not
> > yet going away, though I'd prefer it did. Actually, I wish this behavior
> > never existed, because it makes a lot of assumptions about the way Ruby is
> > implemented. Ask if you want to know more about that.
>
> The semantics of retry outside the context of a rescue makes no sense to
> me.

As I understand, it's like a label in C. Charles' first example is
equivalent to something like this...

#include <stdio.h>
void foo(int (*pf)(const char *f, ...), char *a) {
  (*pf)("%s\n", a);
}
int main() {
retry:
  foo(&printf, "123");
  goto retry;
  return 0;
}

> > I'm looking for input on this. If there's a way to implement it I have
> > missed, please tell me. If you have a concern with this feature being
> > disabled, please tell me (it won't affect retry within rescue blocks). If
> > you want to talk about it more, please tell me.
>
> I recommend an RCR for retry to be available only in a rescue and nowhere
> else. Furthermore, unless this is already the case with a rescue in a
> method (i.e. using the method's implicit exception handling context), retry
> should only rerun the code in the exception handling context and nothing
> outside it (e.g. the method call itself). Unless someone chimes in with a
> really good use case for the other forms of retry, I think they are worse
> than hard to implement -- they are confusing to both the programmer writing
> the code and the programmers reading the code.
>
> > - Charlie
>
> --Greg