[Sugar-devel] HTML activities

C. Scott Ananian cscott at laptop.org
Wed Jan 30 14:36:31 EST 2013


On Wed, Jan 30, 2013 at 12:47 PM, Daniel Narvaez <dwnarvaez at gmail.com>wrote:

> thanks, lots of useful input. I will come back with a more complete
> answer, I need to take the time to look into some of the stuff you
> suggested...
>
> On 30 January 2013 17:35, C. Scott Ananian <cscott at laptop.org> wrote:
> > These APIs should be written in a language-independent manner (think
> about
> > gobject) so that the same basic APIs can be used on multiple platforms.
>
> In the meantime, could you elaborate on what you mean with
> language-independent here?
>

Well, let's take JavaScript, Java, and Python as our example languages.
Let's say there's an API for peer-to-peer messaging. Define it something
like:

class PeerToPeer {
   Peer[] getAllVisiblePeers();
   void sendMessage(Peer p, String message);
}

Now I can easily make a javascript version of this, something like:

var PeerToPeer = Object.create(null);
PeerToPeer.getAllVisiblePeers = function() { return [ ... ]; }
PeerToPeer.sendMessage = function(peer, message) { ... }

I can also make a python version (exercise left to the reader).

In this case I chose to define the API using Java notation, since it is
most explicit about argument and return types.

So basically all I'm saying is try to use good object-oriented practices,
accessor functions, be careful about the types of arguments etc, so that
you can implement basically the identical interface in multiple languages.
Try not to use clever language features (like accessor functions in
javascript) which make it hard to translate your API to a different
language.  Stick to the "common subset" of object-oriented languages.

If you wanted to be extreme about this, you'd write all your APIs in C, and
use gobject bindings (or alternative implementations carefully written to
export the same interfaces as gobject would use for the C API).  But I
think Java is actually a better API-description language for the platforms
likely to be useful for this generation of Sugar.  (Note that I've already
implemented the Java-to-JavaScript bridge for the Android side, so you'd
probably just write a single implementation of the APIs in Java for both
Android-native activities and Web activities on Android.  You've got a
number of different options for the Sugar implementation, but if you wrote
as much as possible in JavaScript (and where necessary, C) you could reuse
that code in a plugin for desktop browsers running in gnome, which might be
convenient for development and some deployments.  Many interesting
behaviors on the Sugar side are just dbus calls, and you ought to be able
to trigger those from JavaScript.)
  --scott

-- 
      ( http://cscott.net )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sugarlabs.org/archive/sugar-devel/attachments/20130130/fe9d1b83/attachment.html>


More information about the Sugar-devel mailing list