[OpenAjaxMobile] Analysis of W3C's latest geolocation APIs and proposals for how to generalize

Jon Ferraiolo jferrai at us.ibm.com
Mon Sep 15 09:17:21 PDT 2008


Hi Paddy,
Yes, good points.

I thought that we had discussed async vs sync back in the May/June
timeframe when I had originally suggested that all APIs should use an async
model, but people pointed out similar concerns as you have below, and as I
remember the async proponents (perhaps just me) conceded that in some cases
a synchronous APIs makes sense. But if doThis(), doThat() and doTheOther()
all have potential response delays, then the developer is stuck with having
to deal with the async programming complexities.

Jon





                                                                           
             "Paddy Byers"                                                 
             <paddy.byers at gmai                                             
             l.com>                                                     To 
             Sent by:                  "OpenAjax Alliance discussion list  
             mobile-bounces at op         on Mobile Ajax"                     
             enajax.org                <mobile at openajax.org>               
                                                                        cc 
                                                                           
             09/15/2008 02:11                                      Subject 
             AM                        Re: [OpenAjaxMobile] Analysis of    
                                       W3C's latest geolocation APIs and   
                                       proposals for how to generalize     
             Please respond to                                             
             OpenAjax Alliance                                             
              discussion list                                              
              on Mobile Ajax                                               
             <mobile at openajax.                                             
                   org>                                                    
                                                                           
                                                                           




Hi,

I like the callback idea, in that the API is the same irrespective of
whether the implementation works synchronously or asynchronously. In
principle, any given implementation could elect either to complete
synchronously or asynchronously depending on the circumstances of the
request.

However, in effect this forces all code to be written to expect
asynchronous behaviour, which can end up with things a lot more awkward.
For example, suppose you wanted to do a sequence of things conventionally:

doThis();
doThat();
doTheOther();

With the callback-possibly-asynchronous style of API (if each successive
call depends on results of the previous call) you'd need to do:

doThis(function() {doThat(function() {doTheOther();});});

So what happens when you want to iterate, eg in the conventional style
you'd do:

while(success) {
  success = pim.addContact(contactsToBeAdded[index++]);
}

?

It seems there isn't an obvious analogue - you can write something that is
potentially recursive (if it happens that the addContact API is
synchronous), or you could initiate a series of potentially asynchronous
calls in parallel and wait for all the results to arrive.

I think if a call is known to be either synchronous or known to be
asynchronous it definitely helps to know, and typically user code would be
written one way or another depending on the expected behaviour. I agree it
is neater to capture both types of behaviour in a single style of API, but
you can also argue that the behaviour should be explicit in the form of the
API, if it is defined, to avoid any possible confusion (either on the part
of users of the API or implementers).

Paddy_______________________________________________
mobile mailing list
mobile at openajax.org
http://openajax.org/mailman/listinfo/mobile
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://openajax.org/pipermail/mobile/attachments/20080915/437bb6a6/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: graycol.gif
Type: image/gif
Size: 105 bytes
Desc: not available
Url : http://openajax.org/pipermail/mobile/attachments/20080915/437bb6a6/attachment.gif 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pic08606.gif
Type: image/gif
Size: 1255 bytes
Desc: not available
Url : http://openajax.org/pipermail/mobile/attachments/20080915/437bb6a6/attachment-0001.gif 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ecblank.gif
Type: image/gif
Size: 45 bytes
Desc: not available
Url : http://openajax.org/pipermail/mobile/attachments/20080915/437bb6a6/attachment-0002.gif 


More information about the mobile mailing list