haxeui / hxWidgets

Haxe externs (and wrappers) for wxWidgets
MIT License
77 stars 23 forks source link

Mimick API completely or "haxeify" #12

Closed ianharrigan closed 8 years ago

ianharrigan commented 8 years ago

In the library there is a set of wrappers on top of the extern classes. There is scope inside here to make library a little more haxe-like, but want to know if anyone thinks its a bad idea or not. Examples would be to use getters and setters instead of getXYZ / setXYZ, so for example instead of:

button.setId(123);
var x = button.getId();

we could use:

button.id = 123;
var x = button.id;

I think personally its a nice option, and its worth noting that already in the wrapper constructors ive changed the param order to make the API a little more usable.

Thoughts?

ibilon commented 8 years ago

For me bringing a library for haxe is about more than just having its api, I think it's important that the wrapper feels like haxe, after all we are coding in haxe, if it feels like c++ might as well use it in c++.

And if someone wants the pure wxWidgets experience there's the extern classes, though they could be better placed in their own package like wx.widgets (and keep the wrapper in hx.widgets).

ianharrigan commented 8 years ago

Cool... i agree totally.

TheSHEEEP commented 8 years ago

Personally, I prefer explicit setters and getters, as it does not hide anything from the user (do I call a function here? Is this maybe a performance impact? Does this even what I want to...) and offers better autocompletion & documentation support in tools.

That said, I agree that a library for platform X should adhere to the standards of that platform as much as the author feels comfortable with, and while I wouldn't say that implicit getters/setters are a standard (maybe more common, though), it is what you do yourself in haxeui, which is what I assume most will use hxWidgets with. And having two different standards there would be weird, indeed.

ianharrigan commented 8 years ago

when you say explicit setters what do you mean exactly? The idea would be:

in wx.widgets (which would match the wxWidgets function signatures):

extern class Something {
    @:native("GetValue") public function getValue():Int;
    @:native("SetValue") public function setValue(value:Int):Void;
}

And then in the haxe wrappers in hx.widgets:

class Something {
    public var something(get, set):Int
    private function get_something():Int {
        return _ref.getSomething();
    }
    private function set_something(value:Int):Int {
        _ref.setSomething(value);
        return value;
    }
}

So the "normal" haxe use would be:

something1.value = something2.value;

which feels more "haxey" than:

something1.setValue(something2.getValue());
TheSHEEEP commented 8 years ago

I mean the wxWidgets function signature with explicit and the public var something(get, set):Int with implicit :)

ianharrigan commented 8 years ago

I think it is done now as part of the restructure. In general if there are GetXXX/SetXXX functions in the API that take single params in Set and return the same type in Get then they are turned in haxe getters setters.

Closing.