Multitypes & JQuery

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

Re: Multitypes & JQuery

Nicolas Cannasse
Le 17/02/2011 14:55, Andy Li a écrit :

> 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;

Yes, they should be separated into two methods :

  text() : String;
  setText( value : String ) : JQuery

- returning Dynamic is not a good idea since we want to have something
well-typed

- partial overloading can be done with @:multitype, but that doesn't
work for return values or exotic cases

- more general overloading can be done by declaring additional methods
and doing a "setText = text" copy in __init__ : this way you also have
access to setText in JS, it makes things more coherent between haXe and JS.

Having full overloading is out of question right now, that would need
more than a hack and if supported for externs, people would - rightfully
- ask it for haXe classes as well, which is not planned.

Hope that makes things clear.

Concerning your jQuery class, yes I had a look at yours and another one
one haxelib, but I wanted to give it a try without relying on Dynamic,
hence this proposal.

Best,
Nicolas

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

Re: Multitypes & JQuery

Justin Donaldson-3
This feature, etc. makes good sense.  I haven't tested yet, but I'm betting it'll work fine for what I needed multitypes for.  You've done a nice job cleaning up the javascript issues, especially the issues with external libraries.

-Justin

On Thu, Feb 17, 2011 at 8:14 AM, Nicolas Cannasse <[hidden email]> wrote:
Le 17/02/2011 14:55, Andy Li a écrit :

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;

Yes, they should be separated into two methods :

 text() : String;
 setText( value : String ) : JQuery

- returning Dynamic is not a good idea since we want to have something well-typed

- partial overloading can be done with @:multitype, but that doesn't work for return values or exotic cases

- more general overloading can be done by declaring additional methods and doing a "setText = text" copy in __init__ : this way you also have access to setText in JS, it makes things more coherent between haXe and JS.

Having full overloading is out of question right now, that would need more than a hack and if supported for externs, people would - rightfully - ask it for haXe classes as well, which is not planned.

Hope that makes things clear.

Concerning your jQuery class, yes I had a look at yours and another one one haxelib, but I wanted to give it a try without relying on Dynamic, hence this proposal.

Best,

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,

I see your reasons. But still I have a concern, that is with current @:multitype, it is also made only for extern, but not a real multitype.
So why not have a @:overload instead of @:multitype, that sounds closer to what other platform is doing.
And the benefits are:
  • no additional documentation for extern as mentioned by Niel
  • no __init__ needed, so the program is both shorter and faster(in the boot stage)
  • things are even more coherent between haXe and JS
  • cases @:multitype can't address, like the return type, are also addressed
@:fakeOverload (or @:nativeOverload) can be used instead of @:overload, so people can have a right expectation.

What do you think?

Best,
Andy

On Fri, Feb 18, 2011 at 12:14 AM, Nicolas Cannasse <[hidden email]> wrote:
Le 17/02/2011 14:55, Andy Li a écrit :

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;

Yes, they should be separated into two methods :

 text() : String;
 setText( value : String ) : JQuery

- returning Dynamic is not a good idea since we want to have something well-typed

- partial overloading can be done with @:multitype, but that doesn't work for return values or exotic cases

- more general overloading can be done by declaring additional methods and doing a "setText = text" copy in __init__ : this way you also have access to setText in JS, it makes things more coherent between haXe and JS.

Having full overloading is out of question right now, that would need more than a hack and if supported for externs, people would - rightfully - ask it for haXe classes as well, which is not planned.

Hope that makes things clear.

Concerning your jQuery class, yes I had a look at yours and another one one haxelib, but I wanted to give it a try without relying on Dynamic, hence this proposal.

Best,

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

Jordo Odroj
Like Andy, I really see a full, native-to-the-language multitype as being something for us to achieve. Right now, I'm trying to get it to work with macros, but it is a little difficult.
Basically, I'd like to see any reference to "Int | String" actually refer to a "hidden" enum that looks as follows:
enum IntOrString {
  Int(i: Int);
  String(s: String);
}

I think I can make a macro such as:
OneFrom(Int, String);
Which can expand out into IntOrString, but I what I really want is for this to be done automatically, any time I declare a method such as:
public function foo(intOrString : Int | String) {
...
}

I can't do this with macros, I've found.

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

I see your reasons. But still I have a concern, that is with current @:multitype, it is also made only for extern, but not a real multitype.
So why not have a @:overload instead of @:multitype, that sounds closer to what other platform is doing.
And the benefits are:
  • no additional documentation for extern as mentioned by Niel
  • no __init__ needed, so the program is both shorter and faster(in the boot stage)
  • things are even more coherent between haXe and JS
  • cases @:multitype can't address, like the return type, are also addressed
@:fakeOverload (or @:nativeOverload) can be used instead of @:overload, so people can have a right expectation.

What do you think?

Best,
Andy

On Fri, Feb 18, 2011 at 12:14 AM, Nicolas Cannasse <[hidden email]> wrote:
Le 17/02/2011 14:55, Andy Li a écrit :

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;

Yes, they should be separated into two methods :

 text() : String;
 setText( value : String ) : JQuery

- returning Dynamic is not a good idea since we want to have something well-typed

- partial overloading can be done with @:multitype, but that doesn't work for return values or exotic cases

- more general overloading can be done by declaring additional methods and doing a "setText = text" copy in __init__ : this way you also have access to setText in JS, it makes things more coherent between haXe and JS.

Having full overloading is out of question right now, that would need more than a hack and if supported for externs, people would - rightfully - ask it for haXe classes as well, which is not planned.

Hope that makes things clear.

Concerning your jQuery class, yes I had a look at yours and another one one haxelib, but I wanted to give it a try without relying on Dynamic, hence this proposal.

Best,

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
12