Property initializers in HaXe

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Property initializers in HaXe

David Peek
Hi all,

Is there any reason in particular why property initializers in HaXe only work for static members? I realize implementing them would require a different approach than statics, but is there any reason why the compiler couldn't just move them to the constructor for you (like mxmlc does I believe).

Of particular frustration is having to initialise properties with setters using Reflect so as to bypass their setter methods. Of course, there might be a more sensible way of achieving that which I'm not aware of... :P

Many thanks,
David
--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Property initializers in HaXe

Juraj Kirchheim
I know this was a topic more than a year ago, and in the end I suppose
its just a design decision not everybody is happy with.

As for your second problem, I suppose you could store the actual data
in a different private variable. If you do not use the
property-variable itself, haXe will never generate it:

var _data:A;
public var data(get_data, set_data):A;
inline function get_data() {
     return _data;
}
function set_data(param:A) {
     this._data = param;
     //perform extra logic
}
public function new() {
       this._data = someA;//setter bypassed
}

Not necessarily pretty, but better than Reflect.setField I suppose ;)

greetz
back2dos


On Wed, Dec 8, 2010 at 4:03 AM, David Peek <[hidden email]> wrote:

> Hi all,
>
> Is there any reason in particular why property initializers in HaXe only work for static members? I realize implementing them would require a different approach than statics, but is there any reason why the compiler couldn't just move them to the constructor for you (like mxmlc does I believe).
>
> Of particular frustration is having to initialise properties with setters using Reflect so as to bypass their setter methods. Of course, there might be a more sensible way of achieving that which I'm not aware of... :P
>
> Many thanks,
> David
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Property initializers in HaXe

Cauê W.
If you do not use the
property-variable itself, haXe will never generate it:
Actually (and sadly) this is not quite true.. you can see the generated output from the targets, and I think no target does that, unfortunately


--
haXe - an open source web programming language
http://haxe.org