var func:Function;
if (type == 1){
func(arg1);
}else if (type == 2{
func(arg1, arg2);
}
function Round (this a:Float):Float {
// rounds the number
}
var a:Float;
a = a.Round();
function Sort (this array:Array<String>):Array<String> {
// sort array
}
var a:Array<String>;
a = a.Sort();
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.
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 ;)
--
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.