Idea for delegating an interface implementation

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

Idea for delegating an interface implementation

Heinz Hölzer-2
and another proposal ;)

just read this article [1] and thought that this could be a nice feature
for haxe.
Maybe it can be combined with the idea of the haxe.magic.Proxy class.

It's delegating an interface implementation.


the current way would be like this:

// create an interface
interface A {
    public function greet (who:String):Void;
    public function plus (a:Int, b:Int):Int;
}

// create a composition class that delegates all method calls.
class AImpl implements A
{
    private var delegateA:A;
   
    public function new (d:A) {
        delegateA = d;
    }
   
    public function greet (who:String) {
        delegateA.greet(who);
    }
   
    public function plus (a:Int, b:Int):Int {
        return delegateA.plus(a,b);
    }
   
}

// the new idea that would rely on a new Syntax.
class AImpl implementsBy(delegateA) A // just a syntax idea
{
    private var delegateA:A;
   
   
    public function new (d:A) {
        delegateA = d;
    }
   
}

// compiler creates delegation methods
class AImpl implements A
{
    private var delegateA:A;
   
    public function new (d:A) {
        delegateA = d;
    }
   
    public function greet (who:String) {
        delegateA.greet(who);
    }
   
    public function plus (a:Int, b:Int):Int {
        return delegateA.plus(a,b);
    }
   
}

Other syntactical ideas

class AImpl implements DelegateProxy<A, delegateA> // I think this is
the best one, because it don't rely on new Keywords
class AImpl implements DelegateProxy<A, delegateA, inline> // with
inline flag, so the compiler creates inline methods

or

class AImpl implements(A, delegateA, inline) A // with inline option

What do you think about the idea?

[1]
http://dobbscodetalk.com/index.php?option=com_myblog&show=Composition-vs-Inheritance.html&Itemid=29 


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

Re: Idea for delegating an interface implementation

Nicolas Cannasse
Heinz Hölzer a écrit :
> and another proposal ;)
[...]
> What do you think about the idea?

IMHO, a programming language is not designed by stockpiling features.

Every single feature of the language need to be carefully thought with
its interactions with all the other features, so it will naturally "fit"
inside the whole specification.

Nicolas

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

Re: Idea for delegating an interface implementation

Chris Hecker

Excellent meta-response...three cheers for Benevolent Dictatorship!

I propose a moratorium on feature requests that are not accompanied by
ocaml diffs of the feature's implementation.

Chris


Nicolas Cannasse wrote:

> Heinz Hölzer a écrit :
>> and another proposal ;)
> [...]
>> What do you think about the idea?
>
> IMHO, a programming language is not designed by stockpiling features.
>
> Every single feature of the language need to be carefully thought with
> its interactions with all the other features, so it will naturally "fit"
> inside the whole specification.
>
> Nicolas
>

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

Re: Idea for delegating an interface implementation

Heinz Hölzer-2
In reply to this post by Nicolas Cannasse
Nicolas Cannasse schrieb:

> Heinz Hölzer a écrit :
>> and another proposal ;)
> [...]
>> What do you think about the idea?
>
> IMHO, a programming language is not designed by stockpiling features.
>
> Every single feature of the language need to be carefully thought with
> its interactions with all the other features, so it will naturally
> "fit" inside the whole specification.
>
> Nicolas
>
You're absolutely right.

I don't expect that a proposol will be implemented right away, but i
think it's important to talk about them.

The current idea of haxe.magic.Proxy that's already on the possible
future feature list goes in the same direction.
So maybe it's possible to combine the ideas, maybe in another way than
suggested by me.

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

Re: Idea for delegating an interface implementation

Mark de Bruijn | Dykam
In reply to this post by Chris Hecker
Are you saying EVERYONE having a good idea has to learn ocaml and its paradims and the compiler structure first, before announcing his idea. And the seeing +- 10 hours of work being rejected?

On Fri, Aug 28, 2009 at 12:28 AM, Chris Hecker <[hidden email]> wrote:

Excellent meta-response...three cheers for Benevolent Dictatorship!

I propose a moratorium on feature requests that are not accompanied by ocaml diffs of the feature's implementation.

Chris



Nicolas Cannasse wrote:
Heinz Hölzer a écrit :
and another proposal ;)
[...]
What do you think about the idea?

IMHO, a programming language is not designed by stockpiling features.

Every single feature of the language need to be carefully thought with its interactions with all the other features, so it will naturally "fit" inside the whole specification.

Nicolas


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



--
Mark

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

Re: Idea for delegating an interface implementation

Chris Hecker

Yep!  :)

The alternative doesn't seem to work very well.

Chris


Mark de Bruijn wrote:

> Are you saying EVERYONE having a good idea has to learn ocaml and its
> paradims and the compiler structure first, before announcing his idea.
> And the seeing +- 10 hours of work being rejected?
>
> On Fri, Aug 28, 2009 at 12:28 AM, Chris Hecker <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>
>     Excellent meta-response...three cheers for Benevolent Dictatorship!
>
>     I propose a moratorium on feature requests that are not accompanied
>     by ocaml diffs of the feature's implementation.
>
>     Chris
>
>
>
>     Nicolas Cannasse wrote:
>
>         Heinz Hölzer a écrit :
>
>             and another proposal ;)
>
>         [...]
>
>             What do you think about the idea?
>
>
>         IMHO, a programming language is not designed by stockpiling
>         features.
>
>         Every single feature of the language need to be carefully
>         thought with its interactions with all the other features, so it
>         will naturally "fit" inside the whole specification.
>
>         Nicolas
>
>
>     --
>     haXe - an open source web programming language
>     http://haxe.org
>
>
>
>
> --
> Mark
>

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

Re: Idea for delegating an interface implementation

Mark de Bruijn | Dykam
Ignoring or commenting them? That works really well.

On Fri, Aug 28, 2009 at 8:59 AM, Chris Hecker <[hidden email]> wrote:

Yep!  :)

The alternative doesn't seem to work very well.

Chris


Mark de Bruijn wrote:
Are you saying EVERYONE having a good idea has to learn ocaml and its paradims and the compiler structure first, before announcing his idea. And the seeing +- 10 hours of work being rejected?

On Fri, Aug 28, 2009 at 12:28 AM, Chris Hecker <[hidden email] <mailto:[hidden email]>> wrote:


   Excellent meta-response...three cheers for Benevolent Dictatorship!

   I propose a moratorium on feature requests that are not accompanied
   by ocaml diffs of the feature's implementation.

   Chris



   Nicolas Cannasse wrote:

       Heinz Hölzer a écrit :

           and another proposal ;)

       [...]

           What do you think about the idea?


       IMHO, a programming language is not designed by stockpiling
       features.

       Every single feature of the language need to be carefully
       thought with its interactions with all the other features, so it
       will naturally "fit" inside the whole specification.

       Nicolas


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




--
Mark


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



--
Mark

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

Re: Idea for delegating an interface implementation

Heinz Hölzer-2
In reply to this post by Nicolas Cannasse
just want to note, that this is not just a crazy idea, delphi for
example offers this feature:

http://prismwiki.codegear.com/en/Implements_%28keyword%29




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

Re: More Consistent Approach

Heinz Hölzer-2
In reply to this post by Nicolas Cannasse
this would be a more consistent approach, without new language constructs

class AImpl implements A
{
   private var delegateA:InterfaceDelegationProxy<A>;
 
   public function new (d:A) {
       delegateA = d;
   }
}

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

Re: More Consistent Approach

Armén
2009/8/28 Heinz Hölzer <[hidden email]>:

> this would be a more consistent approach, without new language constructs
>
> class AImpl implements A
> {
>  private var delegateA:InterfaceDelegationProxy<A>;
>
>  public function new (d:A) {
>      delegateA = d;
>  }
> }
>

Why not write a pre-processor that will let you write your desired
syntax and generate all the code you would otherwise end up typing?
haXe compiler will not be involved in any way, so this moves control
to you. It need not be involved either - it will compile it as it is -
a bunch of functions manually delegating other calls. The difference
is that that source code will be generated from a more abstract syntax
that you will type which will be used as input by pre-processor. This
is meta-programming at its simplest.

> --
> 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: Idea for delegating an interface implementation

Gamehaxe
In reply to this post by Heinz Hölzer-2
I have always wanted a language that supports something like this.
I understand people do not want to "overload" the language, but
in c++ you are forced to do "#define delegate_func1()...." to
get this.

I think of it as

class X implements Y with var_name
{
    var var_name:Y;
}

but I am not fussy about notation.  This would then have good
built-in support for a common design pattern.

Hugh


> and another proposal ;)
>
> just read this article [1] and thought that this could be a nice feature  
> for haxe.
> Maybe it can be combined with the idea of the haxe.magic.Proxy class.
>
> It's delegating an interface implementation.
>
>
> the current way would be like this:
>
> // create an interface
> interface A {
>     public function greet (who:String):Void;
>     public function plus (a:Int, b:Int):Int;
> }
>
> // create a composition class that delegates all method calls.
> class AImpl implements A
> {
>     private var delegateA:A;
>         public function new (d:A) {
>         delegateA = d;
>     }
>         public function greet (who:String) {
>         delegateA.greet(who);
>     }
>         public function plus (a:Int, b:Int):Int {
>         return delegateA.plus(a,b);
>     }
>     }
>
> // the new idea that would rely on a new Syntax.
> class AImpl implementsBy(delegateA) A // just a syntax idea
> {
>     private var delegateA:A;
>             public function new (d:A) {
>         delegateA = d;
>     }
>     }
>
> // compiler creates delegation methods
> class AImpl implements A
> {
>     private var delegateA:A;
>         public function new (d:A) {
>         delegateA = d;
>     }
>         public function greet (who:String) {
>         delegateA.greet(who);
>     }
>         public function plus (a:Int, b:Int):Int {
>         return delegateA.plus(a,b);
>     }
>     }
>
> Other syntactical ideas
>
> class AImpl implements DelegateProxy<A, delegateA> // I think this is  
> the best one, because it don't rely on new Keywords
> class AImpl implements DelegateProxy<A, delegateA, inline> // with  
> inline flag, so the compiler creates inline methods
>
> or
>
> class AImpl implements(A, delegateA, inline) A // with inline option
>
> What do you think about the idea?
>
> [1]
> http://dobbscodetalk.com/index.php?option=com_myblog&show=Composition-vs-Inheritance.html&Itemid=29



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

Re: Idea for delegating an interface implementation

Ron Wheeler
In reply to this post by Mark de Bruijn | Dykam
It would reduce the requests to the really serious deficiencies.
Might also reduce the reliability of haXe.

I think that the English expression describing Chris's comments is
"tongue in cheek " - you can put away the ocaml manual!

Ron

Mark de Bruijn wrote:

> Are you saying EVERYONE having a good idea has to learn ocaml and its
> paradims and the compiler structure first, before announcing his idea.
> And the seeing +- 10 hours of work being rejected?
>
> On Fri, Aug 28, 2009 at 12:28 AM, Chris Hecker <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>
>     Excellent meta-response...three cheers for Benevolent Dictatorship!
>
>     I propose a moratorium on feature requests that are not
>     accompanied by ocaml diffs of the feature's implementation.
>
>     Chris
>
>
>
>     Nicolas Cannasse wrote:
>
>         Heinz Hölzer a écrit :
>
>             and another proposal ;)
>
>         [...]
>
>             What do you think about the idea?
>
>
>         IMHO, a programming language is not designed by stockpiling
>         features.
>
>         Every single feature of the language need to be carefully
>         thought with its interactions with all the other features, so
>         it will naturally "fit" inside the whole specification.
>
>         Nicolas
>
>
>     --
>     haXe - an open source web programming language
>     http://haxe.org
>
>
>
>
> --
> Mark


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