February 14, 2009

opensocial javascript api rants

Opensocial javascript api is very flexible, this is a benefit when there are multiple containers need to implement the same standard. It also allows batch multiple commands. I think people already know its advantages, so I’m not going to rant about advantages. I’m just going to do some ranting about some of the shortcomings that comes with these flexibilities.

1. cumbersome

Instead of one call like:
opensocial.person.getViewer();
it takes 4 lines to do the same thing. The following code is not actual code, it only illustrates the point.
var req = opensocial.newDataRequest();
var personReq = req.newFetchPersonRequest();
req.add(personReq, “…”);
req.send();


2. usually, when there is objects, it is easy to infer the data structure. With getField()/setField() instead of property, it is harder to infer data structure. Also, we don’t get the benefit of the code-helper by IDE.


Solution?

To address #1:
Perhaps we should have some new api call build on top of the existing api to make things more terse:

Eg.
OpensocialShortcut.person.getViewer();
OpensocialShortcut.person.getFriends();
OpensocialShortcut.data.update();
OpensocialShortcut.data.fetch();



To address #2:
On the actionscript api, perhaps we should have extension to allow people to access object properties like this:
person.name.firstName
person.gender.getKey()


instead of
person.getField(opensocial.Person.Field.NAME).getField(opensocial.Name.Field.FIRST_NAME);
person.getField(opensocial.Person.Field.GENDER).getKey();


---------

What do you think? Is it better to have the API call featured like the one shown in “Solution” section?

No comments:

Post a Comment