Multitypes & JQuery

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

Multitypes & JQuery

Nicolas Cannasse
Hi,

I've committed two changes on haXe SVN :

- added js.JQuery as a default in std/js : it is using
haxe.macro.Tools.includeFile to include std/js/jquery-1.5-min.js
directly into the haXe/JS output. This way as soon as you use js.JQuery,
you don't have to include the jquery library as well. This can be
disable with -D noEmbedJS. The js.SWFObject class will soon follow the
same rules.

- added @:multitype metadata support, which is documented here
http://haxe.org/manual/metadata and used by js.JQuery. As a result, I've
decided to drop the original multitype feature proposal, reasons
explained here : http://haxe.org/com/features/dropped

Enjoy !

Nicolas

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

Re: Multitypes & JQuery

clemos
Hi,

This is just awesome.
Great moves these times :)

Cheers,
Clément

On Thu, Feb 17, 2011 at 11:32 AM, Nicolas Cannasse
<[hidden email]> wrote:

> Hi,
>
> I've committed two changes on haXe SVN :
>
> - added js.JQuery as a default in std/js : it is using
> haxe.macro.Tools.includeFile to include std/js/jquery-1.5-min.js directly
> into the haXe/JS output. This way as soon as you use js.JQuery, you don't
> have to include the jquery library as well. This can be disable with -D
> noEmbedJS. The js.SWFObject class will soon follow the same rules.
>
> - added @:multitype metadata support, which is documented here
> http://haxe.org/manual/metadata and used by js.JQuery. As a result, I've
> decided to drop the original multitype feature proposal, reasons explained
> here : http://haxe.org/com/features/dropped
>
> Enjoy !
>
> Nicolas
>
> --
> 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: Multitypes & JQuery

Tony Polinelli
Great!  I would recommend that it also implements Dynamic, so that
when you extend jquery with 3rd party extensions, you can rapidly use
that functionality. Often we have just added an extern method or two
to the class, but just dynamic access is handy too. Have you had any
thoughts about how to handle extensions? I guess you could copy it
into the project and modify-

On Thursday, February 17, 2011, clemos <[hidden email]> wrote:

> Hi,
>
> This is just awesome.
> Great moves these times :)
>
> Cheers,
> Clément
>
> On Thu, Feb 17, 2011 at 11:32 AM, Nicolas Cannasse
> <[hidden email]> wrote:
>> Hi,
>>
>> I've committed two changes on haXe SVN :
>>
>> - added js.JQuery as a default in std/js : it is using
>> haxe.macro.Tools.includeFile to include std/js/jquery-1.5-min.js directly
>> into the haXe/JS output. This way as soon as you use js.JQuery, you don't
>> have to include the jquery library as well. This can be disable with -D
>> noEmbedJS. The js.SWFObject class will soon follow the same rules.
>>
>> - added @:multitype metadata support, which is documented here
>> http://haxe.org/manual/metadata and used by js.JQuery. As a result, I've
>> decided to drop the original multitype feature proposal, reasons explained
>> here : http://haxe.org/com/features/dropped
>>
>> Enjoy !
>>
>> Nicolas
>>
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>>
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
Tony Polinelli
http://touchmypixel.com

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

Re: Multitypes & JQuery

Nicolas Cannasse
Le 17/02/2011 13:39, Tony Polinelli a écrit :
> Great!  I would recommend that it also implements Dynamic, so that
> when you extend jquery with 3rd party extensions, you can rapidly use
> that functionality. Often we have just added an extern method or two
> to the class, but just dynamic access is handy too. Have you had any
> thoughts about how to handle extensions? I guess you could copy it
> into the project and modify-

You can simply subclass js.JQuery and add you extension types + a small
__init__ to bind your class to "jQuery"

Nicolas

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

Re: Multitypes & JQuery

Michiel Crefcoeur
In reply to this post by Nicolas Cannasse
The multitype metadata is a great feature!
I was just reading the proposed multitype solution and I thought of a different method (only for function arguments):

class Example {


  function foo(x:Dynamic){}

  function foo(x:Int){}

  function foo(x:String){}

}

I haven't really thought about any implications, just want to hear your opinion.
This would be very useful when combined with "using".
No runtime type checking required as the compiler would translate calls to foo$1, foo$2, foo$3 for example, based on the argument's type.

Would this be a more feasible solution?

2011/2/17 Nicolas Cannasse <[hidden email]>
Hi,

I've committed two changes on haXe SVN :

- added js.JQuery as a default in std/js : it is using haxe.macro.Tools.includeFile to include std/js/jquery-1.5-min.js directly into the haXe/JS output. This way as soon as you use js.JQuery, you don't have to include the jquery library as well. This can be disable with -D noEmbedJS. The js.SWFObject class will soon follow the same rules.

- added @:multitype metadata support, which is documented here http://haxe.org/manual/metadata and used by js.JQuery. As a result, I've decided to drop the original multitype feature proposal, reasons explained here : http://haxe.org/com/features/dropped

Enjoy !

Nicolas

--
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: Multitypes & JQuery

Nicolas Cannasse
Le 17/02/2011 14:05, Michiel Crefcoeur a écrit :

> The multitype metadata is a great feature!
> I was just reading the proposed multitype solution and I thought of a
> different method (only for function arguments):
>
> class Example {
>
>
>    function foo(x:Dynamic){}
>
>    function foo(x:Int){}
>
>    function foo(x:String){}
>
> }
>
> I haven't really thought about any implications, just want to hear your
> opinion.
> This would be very useful when combined with "using".
> No runtime type checking required as the compiler would translate calls
> to foo$1, foo$2, foo$3 for example, based on the argument's type.
>
> Would this be a more feasible solution?

Not without huge changes in the compiler, since every lookup is based on
function/variable name. A lot of target languages also only support one
single value per name.

Nicolas

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

Re: Multitypes & JQuery

Philipp Klose-2
In reply to this post by Nicolas Cannasse

I will definitely love this feature! It is extremely useful for extern classes (PHP or JS). 

 

Thanks.

Nicolas Cannasse <[hidden email]> hat am 17. Februar 2011 um 11:32 geschrieben:

> Hi,
>
> I've committed two changes on haXe SVN :
>
> - added js.JQuery as a default in std/js : it is using
> haxe.macro.Tools.includeFile to include std/js/jquery-1.5-min.js
> directly into the haXe/JS output. This way as soon as you use js.JQuery,
> you don't have to include the jquery library as well. This can be
> disable with -D noEmbedJS. The js.SWFObject class will soon follow the
> same rules.
>
> - added @:multitype metadata support, which is documented here
> http://haxe.org/manual/metadata and used by js.JQuery. As a result, I've
> decided to drop the original multitype feature proposal, reasons
> explained here : http://haxe.org/com/features/dropped
>
> Enjoy !
>
> Nicolas
>
> --
> 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: Multitypes & JQuery

Andy Li
In reply to this post by Nicolas Cannasse
Hi Nicolas,

It's good to have official support on jQuery!

However I noticed some of the method signatures are not reflecting the real case. 
for example:
    function text( ?value : String ) : String;
should be:
    function text( ?value : String ) : Dynamic;
which if expressed in function overloading is:
    function text() : String;
    function text( value : String ) : JQuery;

And there is a number of APIs not appear in your extern (the TODOs).

Actually I wouldn't mind if you simply use my jQueryExtern, which should have been made as properly as it can, except some changes I want to introduce (not yet done because I don't want to break codes):
  • move into a namespace (maybe js.jquery?)
  • remove the JQuery prefix of JQueryEvent, JQueryDeferred etc.
  • move JQueryS to a property (JQuery.static)
I can make those changes and give you to put it into the core.

What do you think?

Best regards,
Andy

On Thu, Feb 17, 2011 at 6:32 PM, Nicolas Cannasse <[hidden email]> wrote:
Hi,

I've committed two changes on haXe SVN :

- added js.JQuery as a default in std/js : it is using haxe.macro.Tools.includeFile to include std/js/jquery-1.5-min.js directly into the haXe/JS output. This way as soon as you use js.JQuery, you don't have to include the jquery library as well. This can be disable with -D noEmbedJS. The js.SWFObject class will soon follow the same rules.

- added @:multitype metadata support, which is documented here http://haxe.org/manual/metadata and used by js.JQuery. As a result, I've decided to drop the original multitype feature proposal, reasons explained here : http://haxe.org/com/features/dropped

Enjoy !

Nicolas

--
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: Multitypes & JQuery

Andy Li
for @:multitype, it sounds a bit too restrictive that the real function can have only one param...

What about something like:
@:multitype(myA(String,Int), myB(Float,Int))
function myMethod(str:String, myA:Dynamic, myB:Dynamic):Void;

Best,
Andy

On Thu, Feb 17, 2011 at 9:55 PM, Andy Li <[hidden email]> wrote:
Hi Nicolas,

It's good to have official support on jQuery!

However I noticed some of the method signatures are not reflecting the real case. 
for example:
    function text( ?value : String ) : String;
should be:
    function text( ?value : String ) : Dynamic;
which if expressed in function overloading is:
    function text() : String;
    function text( value : String ) : JQuery;

And there is a number of APIs not appear in your extern (the TODOs).

Actually I wouldn't mind if you simply use my jQueryExtern, which should have been made as properly as it can, except some changes I want to introduce (not yet done because I don't want to break codes):
  • move into a namespace (maybe js.jquery?)
  • remove the JQuery prefix of JQueryEvent, JQueryDeferred etc.
  • move JQueryS to a property (JQuery.static)
I can make those changes and give you to put it into the core.

What do you think?

Best regards,
Andy

On Thu, Feb 17, 2011 at 6:32 PM, Nicolas Cannasse <[hidden email]> wrote:
Hi,

I've committed two changes on haXe SVN :

- added js.JQuery as a default in std/js : it is using haxe.macro.Tools.includeFile to include std/js/jquery-1.5-min.js directly into the haXe/JS output. This way as soon as you use js.JQuery, you don't have to include the jquery library as well. This can be disable with -D noEmbedJS. The js.SWFObject class will soon follow the same rules.

- added @:multitype metadata support, which is documented here http://haxe.org/manual/metadata and used by js.JQuery. As a result, I've decided to drop the original multitype feature proposal, reasons explained here : http://haxe.org/com/features/dropped

Enjoy !

Nicolas

--
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: Multitypes & JQuery

Niel Drummond-3
I haven't tried this, just to add a comment.

there are currently some javascript API specs that use method overloading, for example, in the Khronos webgl spec:
 
        WebGLRenderingContext::texSubImage2D(target:GLenum, level:GLint, xoffset:GLint, yoffset:GLint, width:GLsizei, height:GLsizei, format:GLenum, type:GLenum, pixels:WebGLArray):Void;
        WebGLRenderingContext::texSubImage2D(target:GLenum, level:GLint, xoffset:GLint, yoffset:GLint, pixels:ImageData, ?flipY:GLboolean, ?asPremultipliedAlpha:GLboolean):Void;
        WebGLRenderingContext::texSubImage2D(target:GLenum, level:GLint, xoffset:GLint, yoffset:GLint, image:HTMLImageElement, ?flipY:GLboolean, ?asPremultipliedAlpha:GLboolean):Void;
        WebGLRenderingContext::texSubImage2D(target:GLenum, level:GLint, xoffset:GLint, yoffset:GLint, image:HTMLCanvasElement, ?flipY:GLboolean, ?asPremultipliedAlpha:GLboolean):Void;
        WebGLRenderingContext::texSubImage2D(target:GLenum, level:GLint, xoffset:GLint, yoffset:GLint, image:HTMLVideoElement, ?flipY:GLboolean, ?asPremultipliedAlpha:GLboolean):Void;

this isn't easily implemented in an extern, perhaps @multitype can help this situation, though from the documentation it isn't immediately obvious how to.

- Niel

On Thu, Feb 17, 2011 at 10:05:48PM +0800, Andy Li wrote:

> for @:multitype, it sounds a bit too restrictive that the real function can
> have only one param...
>
> What about something like:
> @:multitype(myA(String,Int), myB(Float,Int))
> function myMethod(str:String, myA:Dynamic, myB:Dynamic):Void;
>
> Best,
> Andy
>
> On Thu, Feb 17, 2011 at 9:55 PM, Andy Li <[hidden email]> wrote:
>
> > Hi Nicolas,
> >
> > It's good to have official support on jQuery!
> >
> > However I noticed some of the method signatures are not reflecting the real
> > case.
> > for example:
> >     function text( ?value : String ) : String;
> > should be:
> >     function text( ?value : String ) : Dynamic;
> > which if expressed in function overloading is:
> >     function text() : String;
> >     function text( value : String ) : JQuery;
> >
> > And there is a number of APIs not appear in your extern (the TODOs).
> >
> > Actually I wouldn't mind if you simply use my jQueryExtern<http://lib.haxe.org/p/jQueryExtern>,
> > which should have been made as properly as it can, except some changes I
> > want to introduce (not yet done because I don't want to break codes):
> >
> >    - move into a namespace (maybe js.jquery?)
> >    - remove the JQuery prefix of JQueryEvent, JQueryDeferred etc.
> >    - move JQueryS to a property (JQuery.static)
> >
> > I can make those changes and give you to put it into the core.
> >
> > What do you think?
> >
> > Best regards,
> > Andy
> >
> > On Thu, Feb 17, 2011 at 6:32 PM, Nicolas Cannasse <
> > [hidden email]> wrote:
> >
> >> Hi,
> >>
> >> I've committed two changes on haXe SVN :
> >>
> >> - added js.JQuery as a default in std/js : it is using
> >> haxe.macro.Tools.includeFile to include std/js/jquery-1.5-min.js directly
> >> into the haXe/JS output. This way as soon as you use js.JQuery, you don't
> >> have to include the jquery library as well. This can be disable with -D
> >> noEmbedJS. The js.SWFObject class will soon follow the same rules.
> >>
> >> - added @:multitype metadata support, which is documented here
> >> http://haxe.org/manual/metadata and used by js.JQuery. As a result, I've
> >> decided to drop the original multitype feature proposal, reasons explained
> >> here : http://haxe.org/com/features/dropped
> >>
> >> Enjoy !
> >>
> >> Nicolas
> >>
> >> --
> >> haXe - an open source web programming language
> >> http://haxe.org
> >>
> >
> >

> --
> 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: Multitypes & JQuery

Andy Li
In reply to this post by Andy Li
It would be so nice if it is:

@overload(Void->String)
@overload(String->JQuery)
function text( ?value : String ) : Dynamic;

Best,
Andy
(Sorry to send multiple mails... I don't do it often, but it's exciting to see the changes :p)

On Thu, Feb 17, 2011 at 9:55 PM, Andy Li <[hidden email]> wrote:
Hi Nicolas,

It's good to have official support on jQuery!

However I noticed some of the method signatures are not reflecting the real case. 
for example:
    function text( ?value : String ) : String;
should be:
    function text( ?value : String ) : Dynamic;
which if expressed in function overloading is:
    function text() : String;
    function text( value : String ) : JQuery;

And there is a number of APIs not appear in your extern (the TODOs).

Actually I wouldn't mind if you simply use my jQueryExtern, which should have been made as properly as it can, except some changes I want to introduce (not yet done because I don't want to break codes):
  • move into a namespace (maybe js.jquery?)
  • remove the JQuery prefix of JQueryEvent, JQueryDeferred etc.
  • move JQueryS to a property (JQuery.static)
I can make those changes and give you to put it into the core.

What do you think?

Best regards,
Andy

On Thu, Feb 17, 2011 at 6:32 PM, Nicolas Cannasse <[hidden email]> wrote:
Hi,

I've committed two changes on haXe SVN :

- added js.JQuery as a default in std/js : it is using haxe.macro.Tools.includeFile to include std/js/jquery-1.5-min.js directly into the haXe/JS output. This way as soon as you use js.JQuery, you don't have to include the jquery library as well. This can be disable with -D noEmbedJS. The js.SWFObject class will soon follow the same rules.

- added @:multitype metadata support, which is documented here http://haxe.org/manual/metadata and used by js.JQuery. As a result, I've decided to drop the original multitype feature proposal, reasons explained here : http://haxe.org/com/features/dropped

Enjoy !

Nicolas

--
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: Multitypes & JQuery

Michiel Crefcoeur
Speaking of multitypes/overloading, I've been wondering why this (kinda related) syntax is supported:

function foo(myArg:Int, myArg:String, ?myArg:Int, myArg:Float) {
  trace(myArg);
}

This is allowed but it doesn't seem to really add anything.
The behavior (in javascript at least) is as follows:
- The arguments are renamed to myArg, myArg1, myArg2 and myArg3.
- Any references in the function body to myArg are renamed to the last argument's name: myArg3.

Is there some kind of undocumented feature (since the compiler clearly anticipates duplicate names) that uses this behavior or is it something that should not be allowed?
Second: could this somehow be (ab)used for multitypes?

Best,
Michiel.

2011/2/17 Andy Li <[hidden email]>
It would be so nice if it is:

@overload(Void->String)
@overload(String->JQuery)
function text( ?value : String ) : Dynamic;

Best,
Andy
(Sorry to send multiple mails... I don't do it often, but it's exciting to see the changes :p)

On Thu, Feb 17, 2011 at 9:55 PM, Andy Li <[hidden email]> wrote:
Hi Nicolas,

It's good to have official support on jQuery!

However I noticed some of the method signatures are not reflecting the real case. 
for example:
    function text( ?value : String ) : String;
should be:
    function text( ?value : String ) : Dynamic;
which if expressed in function overloading is:
    function text() : String;
    function text( value : String ) : JQuery;

And there is a number of APIs not appear in your extern (the TODOs).

Actually I wouldn't mind if you simply use my jQueryExtern, which should have been made as properly as it can, except some changes I want to introduce (not yet done because I don't want to break codes):
  • move into a namespace (maybe js.jquery?)
  • remove the JQuery prefix of JQueryEvent, JQueryDeferred etc.
  • move JQueryS to a property (JQuery.static)
I can make those changes and give you to put it into the core.

What do you think?

Best regards,
Andy

On Thu, Feb 17, 2011 at 6:32 PM, Nicolas Cannasse <[hidden email]> wrote:
Hi,

I've committed two changes on haXe SVN :

- added js.JQuery as a default in std/js : it is using haxe.macro.Tools.includeFile to include std/js/jquery-1.5-min.js directly into the haXe/JS output. This way as soon as you use js.JQuery, you don't have to include the jquery library as well. This can be disable with -D noEmbedJS. The js.SWFObject class will soon follow the same rules.

- added @:multitype metadata support, which is documented here http://haxe.org/manual/metadata and used by js.JQuery. As a result, I've decided to drop the original multitype feature proposal, reasons explained here : http://haxe.org/com/features/dropped

Enjoy !

Nicolas

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



--
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: Multitypes & JQuery

Franco Ponticelli
In reply to this post by Andy Li
On Thu, Feb 17, 2011 at 2:31 PM, Andy Li <[hidden email]> wrote:
It would be so nice if it is:

@overload(Void->String)
@overload(String->JQuery)
function text( ?value : String ) : Dynamic;

 What about the following?

@native("text") function getText() : String
@native("text") function setText(value : String) : JQuery
@native("text") function setTextHandler(h : Int -> String -> String) : JQuery

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

Re: Multitypes & JQuery

Cauê W.
this is the syntax I'm using for the C# target right now

2011/2/17 Franco Ponticelli <[hidden email]>
On Thu, Feb 17, 2011 at 2:31 PM, Andy Li <[hidden email]> wrote:
It would be so nice if it is:

@overload(Void->String)
@overload(String->JQuery)
function text( ?value : String ) : Dynamic;

 What about the following?

@native("text") function getText() : String
@native("text") function setText(value : String) : JQuery
@native("text") function setTextHandler(h : Int -> String -> String) : JQuery

--
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: Multitypes & JQuery

Andy Li
In reply to this post by Franco Ponticelli
Hi Franco,

Of course it works, but it lose the beauty of method loading.

For example, when there is:
function setColor(hex:Int):Void;
function setColor(r:Int,g:Int,b:Int):Void;
function setColor(r:Int,g:Int,b:Int, a:Int):Void;
function setColor(r:Float,g:Float,b:Float):Void;
function setColor(r:Float,g:Float,b:Float, a:Float):Void;
function setColor(colorName:String):Void;

You will have to give a unique name for each of them or simply use:
function setColor(a:Dynamic, ?b:Dynamic, ?c:Dynamic):Void;

Best,
Andy

On Thu, Feb 17, 2011 at 10:51 PM, Franco Ponticelli <[hidden email]> wrote:
On Thu, Feb 17, 2011 at 2:31 PM, Andy Li <[hidden email]> wrote:
It would be so nice if it is:

@overload(Void->String)
@overload(String->JQuery)
function text( ?value : String ) : Dynamic;

 What about the following?

@native("text") function getText() : String
@native("text") function setText(value : String) : JQuery
@native("text") function setTextHandler(h : Int -> String -> String) : JQuery


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

Re: Multitypes & JQuery

Franco Ponticelli
I understand that but I do not find it a big limitation ... actually I think it makes the code more readable (not shorter that for sure, but this is the work for a good minificator). In your example:

setColor(hex : Int)
setColorRGB(...) // the float version can be set as the same as the int version
setColorRGBA(...)
setColorByName(...)

On Thu, Feb 17, 2011 at 3:08 PM, Andy Li <[hidden email]> wrote:
Hi Franco,

Of course it works, but it lose the beauty of method loading.

For example, when there is:
function setColor(hex:Int):Void;
function setColor(r:Int,g:Int,b:Int):Void;
function setColor(r:Int,g:Int,b:Int, a:Int):Void;
function setColor(r:Float,g:Float,b:Float):Void;
function setColor(r:Float,g:Float,b:Float, a:Float):Void;
function setColor(colorName:String):Void;

You will have to give a unique name for each of them or simply use:
function setColor(a:Dynamic, ?b:Dynamic, ?c:Dynamic):Void;

Best,
Andy

On Thu, Feb 17, 2011 at 10:51 PM, Franco Ponticelli <[hidden email]> wrote:
On Thu, Feb 17, 2011 at 2:31 PM, Andy Li <[hidden email]> wrote:
It would be so nice if it is:

@overload(Void->String)
@overload(String->JQuery)
function text( ?value : String ) : Dynamic;

 What about the following?

@native("text") function getText() : String
@native("text") function setText(value : String) : JQuery
@native("text") function setTextHandler(h : Int -> String -> String) : JQuery



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

Re: Multitypes & JQuery

Cauê W.
In reply to this post by Andy Li
hey andy!

When I started with the C# target, I really was considering trying to implement method overloading on haxe. And what I really understood is that method overloading isn't really compatible with haxe. That's because it imposes a very higher strain on the runtime when using reflection, and this doesn't make sense on a language that makes so much use of reflection and anonymous types.

So... I think it would be best to remap the function names to something else, which is a little uglier, but much more cross-target effective.

2011/2/17 Andy Li <[hidden email]>
Hi Franco,

Of course it works, but it lose the beauty of method loading.

For example, when there is:
function setColor(hex:Int):Void;
function setColor(r:Int,g:Int,b:Int):Void;
function setColor(r:Int,g:Int,b:Int, a:Int):Void;
function setColor(r:Float,g:Float,b:Float):Void;
function setColor(r:Float,g:Float,b:Float, a:Float):Void;
function setColor(colorName:String):Void;

You will have to give a unique name for each of them or simply use:
function setColor(a:Dynamic, ?b:Dynamic, ?c:Dynamic):Void;

Best,
Andy

On Thu, Feb 17, 2011 at 10:51 PM, Franco Ponticelli <[hidden email]> wrote:
On Thu, Feb 17, 2011 at 2:31 PM, Andy Li <[hidden email]> wrote:
It would be so nice if it is:

@overload(Void->String)
@overload(String->JQuery)
function text( ?value : String ) : Dynamic;

 What about the following?

@native("text") function getText() : String
@native("text") function setText(value : String) : JQuery
@native("text") function setTextHandler(h : Int -> String -> String) : JQuery


--
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: Multitypes & JQuery

Niel Drummond-3
In reply to this post by Franco Ponticelli
Hi,

The limitation is you have to redocument a well documented API, and force your users to learn a different API than the target language.

- Niel

On Thu, Feb 17, 2011 at 03:21:36PM +0000, Franco Ponticelli wrote:

> I understand that but I do not find it a big limitation ... actually I think
> it makes the code more readable (not shorter that for sure, but this is the
> work for a good minificator). In your example:
>
> setColor(hex : Int)
> setColorRGB(...) // the float version can be set as the same as the int
> version
> setColorRGBA(...)
> setColorByName(...)
>
> On Thu, Feb 17, 2011 at 3:08 PM, Andy Li <[hidden email]> wrote:
>
> > Hi Franco,
> >
> > Of course it works, but it lose the beauty of method loading.
> >
> > For example, when there is:
> > function setColor(hex:Int):Void;
> > function setColor(r:Int,g:Int,b:Int):Void;
> > function setColor(r:Int,g:Int,b:Int, a:Int):Void;
> > function setColor(r:Float,g:Float,b:Float):Void;
> > function setColor(r:Float,g:Float,b:Float, a:Float):Void;
> > function setColor(colorName:String):Void;
> >
> > You will have to give a unique name for each of them or simply use:
> > function setColor(a:Dynamic, ?b:Dynamic, ?c:Dynamic):Void;
> >
> > Best,
> > Andy
> >
> > On Thu, Feb 17, 2011 at 10:51 PM, Franco Ponticelli <
> > [hidden email]> wrote:
> >
> >> On Thu, Feb 17, 2011 at 2:31 PM, Andy Li <[hidden email]> wrote:
> >>
> >>> It would be so nice if it is:
> >>>
> >>> @overload(Void->String)
> >>> @overload(String->JQuery)
> >>> function text( ?value : String ) : Dynamic;
> >>>
> >>
> >>  What about the following?
> >>
> >> @native("text") function getText() : String
> >> @native("text") function setText(value : String) : JQuery
> >> @native("text") function setTextHandler(h : Int -> String -> String) :
> >> JQuery
> >>
> >
> >

> --
> 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: Multitypes & JQuery

Franco Ponticelli
The limitation is you have to redocument a well documented API, and force your users to learn a different API than the target language.

This is probably true, but it is also true that renaming methods this way fundamentally reduces the need for documentation. If the editor supports autocompletion I guess you have enough info to make your choice without having to go to the api doc.
Also the @:multitype option doesn't address the return type in any way and for sure doesn't address the function calls that takes different kind/number of arguments ... the autocompletion will be even more confusing than using just one argument of type Dynamic.


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

Re: Multitypes & JQuery

Andy Li
In reply to this post by Cauê W.
Hi Cauê,

Yes, I understand. What I'm asking for is just a compiler feature that is useful for extern.
For my suggestion, the compiler does not check the function implementation with the @:overload metadata, but the function is used as if it is what the @:overload metadata describes.
One can use it like below, but it is not the main usage of the feature:

@overload(Void->String)
@overload(String->JQuery)
public function text( ?value : String ) : Dynamic {
    if (value == null)
        return "123";
    else
        return new JQuery();
}

Best,
Andy

On Thu, Feb 17, 2011 at 11:26 PM, Cauê Waneck <[hidden email]> wrote:
hey andy!

When I started with the C# target, I really was considering trying to implement method overloading on haxe. And what I really understood is that method overloading isn't really compatible with haxe. That's because it imposes a very higher strain on the runtime when using reflection, and this doesn't make sense on a language that makes so much use of reflection and anonymous types.

So... I think it would be best to remap the function names to something else, which is a little uglier, but much more cross-target effective.

2011/2/17 Andy Li <[hidden email]>
Hi Franco,

Of course it works, but it lose the beauty of method loading.

For example, when there is:
function setColor(hex:Int):Void;
function setColor(r:Int,g:Int,b:Int):Void;
function setColor(r:Int,g:Int,b:Int, a:Int):Void;
function setColor(r:Float,g:Float,b:Float):Void;
function setColor(r:Float,g:Float,b:Float, a:Float):Void;
function setColor(colorName:String):Void;

You will have to give a unique name for each of them or simply use:
function setColor(a:Dynamic, ?b:Dynamic, ?c:Dynamic):Void;

Best,
Andy

On Thu, Feb 17, 2011 at 10:51 PM, Franco Ponticelli <[hidden email]> wrote:
On Thu, Feb 17, 2011 at 2:31 PM, Andy Li <[hidden email]> wrote:
It would be so nice if it is:

@overload(Void->String)
@overload(String->JQuery)
function text( ?value : String ) : Dynamic;

 What about the following?

@native("text") function getText() : String
@native("text") function setText(value : String) : JQuery
@native("text") function setTextHandler(h : Int -> String -> String) : JQuery


--

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


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


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