Does Haxe support all the features of AS3 language?

121 views
Skip to first unread message

harsh...@gmail.com

unread,
Feb 24, 2014, 2:49:36 AM2/24/14
to haxe...@googlegroups.com
I've been reading this great comparison and Haxe language is all strongly typed like .NET. This is really good. However I have some questions.


Function types

In my AS3 code I use "var callback:Function" a lot. In haxe is this possible or would you have to strongly type it like "String->Void". What if the Function I want has different signatures, in AS3 I can do this using :

 var func:Function;
 if (type == 1){
    func(arg1);
 }else if (type == 2{
    
func(arg1, arg2);
 }

Would something like this be possible in Haxe? Would I use Dynamic?


Properties

Proprerties need an extra line of code in Haxe. Have any of you found this troublesome? What are the advantages to this syntax? Its quite unusual.


Array types

If I declare Array<int> haxe will output this as Vector<int>? Is there a way to declare a strongly typed Array<int> and yet have it output as humble Array? Many times array is faster than vector, Vector is only faster in case of int, Number and few others. When dealing with objects such as Array<Enemy>, Vector will always be slower than humble Array. Is this possible?


Primitive types

In haxe why is Double called Float? In all languages Float refers to 4 byte floating point, but in Haxe 8 byte doubles must be written as Float? Am I correct? Is there any reason for this convention?


Extension methods

I've used extensions in C# and its very useful. Does Haxe also have extension methods. Can I define this:

function Round (this a:Float):Float {
   // rounds the number
}

var a:Float;
a = a.Round(); 

And even for array types?

function Sort (this array:Array<String>):Array<String> {
   // sort array
}
 
var a:Array<String>;
a = a.Sort(); 


Other targets

Can I take any Haxe code and it will compile ok in other languages like PHP, JS, C++? At least simple functions for numbers, ints, arrays etc?

Simon Krajewski

unread,
Feb 24, 2014, 3:03:26 AM2/24/14
to haxe...@googlegroups.com


On 24 Feb 2014 08:49, <harsh...@gmail.com> wrote:
>
> I've been reading this great comparison and Haxe language is all strongly typed like .NET. This is really good. However I have some questions.
>
>
> Function types
>
> In my AS3 code I use "var callback:Function" a lot. In haxe is this possible or would you have to strongly type it like "String->Void". What if the Function I want has different signatures, in AS3 I can do this using :
>
>>  var func:Function;
>>
>>  if (type == 1){
>>     func(arg1);
>>  }else if (type == 2{
>>     func(arg1, arg2);
>>
>>  }
>
>
> Would something like this be possible in Haxe? Would I use Dynamic?

Yes, you would be using Dynamic.

>
>
> Properties
>
> Proprerties need an extra line of code in Haxe. Have any of you found this troublesome? What are the advantages to this syntax? Its quite unusual.
>
>
> Array types
>
> If I declare Array<int> haxe will output this as Vector<int>? Is there a way to declare a strongly typed Array<int> and yet have it output as humble Array? Many times array is faster than vector, Vector is only faster in case of int, Number and few others. When dealing with objects such as Array<Enemy>, Vector will always be slower than humble Array. Is this possible?

[citation needed]? Anyway, Array is not compiled to Vector. You can use haxe.ds.Vector.

>
>
> Primitive types
>
> In haxe why is Double called Float? In all languages Float refers to 4 byte floating point, but in Haxe 8 byte doubles must be written as Float? Am I correct? Is there any reason for this convention?
>
>
> Extension methods
>
> I've used extensions in C# and its very useful. Does Haxe also have extension methods. Can I define this:
>
>> function Round (this a:Float):Float {
>>    // rounds the number
>> }
>>
>>
>> var a:Float;
>> a = a.Round(); 
>
>
> And even for array types?
>
>> function Sort (this array:Array<String>):Array<String> {
>>    // sort array
>> }
>>
>>  
>>
>> var a:Array<String>;
>> a = a.Sort(); 
>
>
>

Check out https://github.com/HaxeFoundation/HaxeManual/blob/master/md/manual/lf-static-extension.md

> Other targets
>
> Can I take any Haxe code and it will compile ok in other languages like PHP, JS, C++? At least simple functions for numbers, ints, arrays etc?

Yes, as long as you avoid target-specific packages.

>
> --
> To post to this group haxe...@googlegroups.com
> http://groups.google.com/group/haxelang?hl=en
> ---
> You received this message because you are subscribed to the Google Groups "Haxe" group.
> For more options, visit https://groups.google.com/groups/opt_out.

Philippe Elsass

unread,
Feb 24, 2014, 4:03:28 AM2/24/14
to haxe...@googlegroups.com

The benefit of the properties syntax is that most of the time you don't need to write the getter or setter function: using the "default" keyword will automatically create a trivial function - that's actually less typing for you ;)

Juraj Kirchheim

unread,
Feb 24, 2014, 5:00:42 AM2/24/14
to haxe...@googlegroups.com
Not quite accurate: default does not create a function. A plain field
is in fact becomes `(default, default)` down the road.
But yes, `(default, null)` is certainly more succinct than the AS3 equivalent.

Regards,
Juraj

Philippe Elsass

unread,
Feb 24, 2014, 5:28:36 AM2/24/14
to haxe...@googlegroups.com
Oops right, default doesn't generate a function.

What I meant is that you can have var foo(default, set) so you can only write the setter function and not the trivial getter - and as Juraj noted, it won't even be a function be a direct field access.


--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/groups/opt_out.



--
Philippe
Reply all
Reply to author
Forward
0 new messages