Hi guys
After the alpha version of Cocos2d-html5 is launched, we have received many feedback. It quickly came to our attention that we need to “prettify” our API :),
We had a video chat with Ricardo Quesada and Rolando Abarca discussed these cases, the conclusion is that we had a list to choice, and need your feedback to see what is preferred by most developers.
We need to decide these following:
Namespace
-
cc
* sample: var monster = new cc.Sprite;
* pros: short, easy to type, maybe good for performance
* cons: What’s cc stands for? conflict with existing popular js framework? -
CC (capital letters)
* same as above -
cocos2d
* sample: var monster = new cocos2d.Sprite;
* pros: full meaning
* cons: very long to type -
cocos
* sample: var monster = new cocos.Sprite;
* pros: the in betweener of cc and cocos2d
* cons: the same to pros
Property access
-
monster.position.x = 100; var pos = monster.position;
* pros: easy to use, very readable
* cons: The setter is harder to rewrite, cannot chain methods like jQuery
* Ref:https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/defineProperty -
monster.position(100,200); var pos = monster.position();
* pros: jQuery Style, use same function for both set and get
* cons: might affect performance, because it have to check if there is any parameters passed in -
monster.setPosition(100,200); var pos = monster.getPosition();
* pros: Explicit use of set and get, easy to rewrite
* cons: more characters to type
Object Constructor
Note: chained setter functions will be decided in question 2
-
var a = new Sprite(); a.setFile(…).setPosition(…); OR var a = (new Sprite()).setFile(…).setPosition(…);
* pros: classic object creation, chaining is possible when you put new in bracket
* cons: 2 lines of code if not chained, very ugly chain, fails if you forget bracket with new -
var a = Sprite().setFile(…).setPosition(…);
* pros: easy chaining, 1 line, nice to the eye
* cons: no “new” keyword, you could not tell this line creates an object -
var a = Sprite.spriteWithFile(…).setPosition(…);
* pros: easy chain, same as Cocos2d-x
* cons: no “new” keyword, looks C++ ish
please participate this online survey here:
{{iframe(http://www.surveymonkey.com/s/NQJC7BN, 650, 750)}}
Thank you!