jsxgraph icon indicating copy to clipboard operation
jsxgraph copied to clipboard

method naming conventions for dynamic language translation.

Open geometryzen opened this issue 11 years ago • 2 comments

I have a request that JSXGraph functions expected to be called in conjunction with the 'new' prefix follow the convention of uppercase first character of the function name whereas functions that aren't called with the 'new' prefix use lowercase. This would help in the usability of the API as well as (my particular use case) facilitate automated language translation e.g., JavaScript to Python. Examples that go against this convention are few but crucial: X(), Y(), Value(). It would be nice if JSXGraph could add the lowercase versions and deprecate the non-standard versions.

geometryzen avatar Apr 06 '14 00:04 geometryzen

This suggestions is certainly justified from the programming language point of view. In a certain sense we were ahead of our time when we used capital letters for X(), Y() and Value(), because this is now default for public methods in golang. But justified or not, I fear we are not able to change this, because so many applications rely on it.

Wouldn't it be possible for you to work with a small interface where you define the methods you need? Like: JXG.Point.prototype.x = function() { return this.X(); }; JXG.Point.prototype.y = function() { return this.Y(); };

Best wishes, Alfred

alfredwassermann avatar Apr 09 '14 11:04 alfredwassermann

Alfred, Thanks for the history lesson. Perspective is 80%, as they say! I totally appreciate your concern for backwards compatibility and endorse that 100%. I was more thinking along the lines of some redundancy in the JXG API or a deprecation that does not happen - maybe ever! One idea might be to use ecma 5 getter/setter to implement more elegant API that makes these 'properties' look less like functions? Just an idea to kick around - I also appreciate that extra stuff in your API may not be tasteful. I've done a workaround that does not involve messing with your prototype; I'm generally not in favor of that even though it is quite a clean solution for me. Thanks for your consideration. Best Wishes, David

On Wed, Apr 9, 2014 at 7:16 AM, alfredwassermann [email protected]:

This suggestions is certainly justified from the programming language point of view. In a certain sense we were ahead of our time when we used capital letters for X(), Y() and Value(), because this is now default for public methods in golang. But justified or not, I fear we are not able to change this, because so many applications rely on it.

Wouldn't it be possible for you to work with a small interface where you define the methods you need? Like: JXG.Point.prototype.x = function() { return this.X(); }; JXG.Point.prototype.y = function() { return this.Y(); };

Best wishes, Alfred

Reply to this email directly or view it on GitHubhttps://github.com/jsxgraph/jsxgraph/issues/89#issuecomment-39952540 .

geometryzen avatar Apr 12 '14 13:04 geometryzen