On 14 June 2011 11:57, Fabrizio Giudici <[email protected]>wrote:

> You have a service, which is about getting some data by a getData() method.
> Instead of synchronously returning the data, the method notifies (possibly
> later) a callback:
>
> service.getData(callback);
>
> The callback exposes these methods:
>
> public interface Callback
>  {
>     public void notifyNoData();
>
>     public void notifyData (Datum datum);
>
>     public void notifyDataCouldBeRetrieved (ConfirmationCallback
> confirmationCallback);
>  }
>
> The first two methods are obvious. When the third is called, to confirm the
> operation you have to call a doRetrieve() method on the
> ConfirmationCallback:
>
> public interface ConfirmationCallback
>  {
>     public void doRetrieve();
>  }
>
>
> I've been playing with this design since a few time for UI design; and I'm
> going to blog about it. I usually refer to this as "async message style",
> but I'm almost sture there's a more specific name for it. Which one?
> Searching around it seems that there are some similarities with CPS
> (Continuation-Passing Style), but I'm really dubious about that (my
> understanding of Continuations is very different; but perhaps CPS is
> different than "pure" Continuations?). I've found some references to CPS,
> including some code samples, and some make me think this is CPS, others not
> (especially those dealing with variations on tail recursion or stackless
> implementations - perhaps they are just different scenarios than mine,
> perhaps the CPS is a totally different thing).
>
>
This absolutely *is* a limited example of CPS, albeit complicated by the
need to encode first-class functions as SAM types.  Taken to a logical
conclusion, every function in the design takes an argument to the "next"
function that should be called - a guaranteed stack overflow in Java.

The current approach taken by Scala/C# is therefore reification of
*delimited* continuations to stop you blowing the stack.  This isn't exactly
an easy thing to get right, hence the fact that it's a fairly recent arrival
(the growing popularity of asynchronous designs, and the usefulness of
continuations for these have also helped spur adoption)

-- 
You received this message because you are subscribed to the Google Groups "The 
Java Posse" 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/javaposse?hl=en.

Reply via email to