View mode: basic / threaded / horizontal-split · Log in · Help
July 26, 2004
Dynamic Proxies, dare anyone get their hopes up?
One of the nicer features of working on Java and other byte-code
derived languages is the concept of generative programming.  One
of the most common ideas is the dynamic proxy.  The dynamic proxy
allows someone to create a class that implements one or more interfaces
to implement some feature on a class that is already implemented.

One of the best examples of where it really works to the developer's
benefit is making it easy to generate a stub proxy.  For example, if
one wants to connect to a web service through SOAP, the dynamic proxy
will use the interface to the web service, with the SOAP engine
generating proxy code to wrap the method calls.

This is only one case where it works to advantage.  I take this for
granted with Java, would this always have to be something done outside
the D language?  I.e. generate source code and then have the compiler
compile it for me?  (Not very dynamic, huh?)

Of course, one wonders about the possibilities of embedding scripting
languages in a D program for just this type of thing?
July 26, 2004
Re: Dynamic Proxies, dare anyone get their hopes up?
Berin Loritsch wrote:
> One of the nicer features of working on Java and other byte-code
> derived languages is the concept of generative programming.  One
> of the most common ideas is the dynamic proxy.  The dynamic proxy
> allows someone to create a class that implements one or more interfaces
> to implement some feature on a class that is already implemented.
> 
> One of the best examples of where it really works to the developer's
> benefit is making it easy to generate a stub proxy.  For example, if
> one wants to connect to a web service through SOAP, the dynamic proxy
> will use the interface to the web service, with the SOAP engine
> generating proxy code to wrap the method calls.
> 
> This is only one case where it works to advantage.  I take this for
> granted with Java, would this always have to be something done outside
> the D language?  I.e. generate source code and then have the compiler
> compile it for me?  (Not very dynamic, huh?)
> 
> Of course, one wonders about the possibilities of embedding scripting
> languages in a D program for just this type of thing?

I had some ideas concerning a macro extension based on the one 
implemented in Nemerle. <http://nemerle.org>  Basically, a 'macro' 
recieves a piece of syntax from the document, and returns a new AST node 
which is injected in the macro's place.  (about two thirds of Nemerle's 
'core' syntax is implemented with these things)

Along with a hundred other potentially interesting things, such a 
mechanism would make it pretty simple to write a decorator which 
iterates over the contents of a class and inserts extra reflection 
information.  (or generating language bindings)

For the moment, though, it remains little more than the frantic 
scribblings of a madman. :)

On the upside, D is pretty easy to parse: it wouldn't be hard to write a 
little Python script that scans the source and generates more source 
from it.

 -- andy
July 26, 2004
Re: Dynamic Proxies, dare anyone get their hopes up?
Andy Friesen wrote:
> Berin Loritsch wrote:
> 
>> One of the nicer features of working on Java and other byte-code
>> derived languages is the concept of generative programming.  One
>> of the most common ideas is the dynamic proxy.  The dynamic proxy
>> allows someone to create a class that implements one or more interfaces
>> to implement some feature on a class that is already implemented.
>>
>> One of the best examples of where it really works to the developer's
>> benefit is making it easy to generate a stub proxy.  For example, if
>> one wants to connect to a web service through SOAP, the dynamic proxy
>> will use the interface to the web service, with the SOAP engine
>> generating proxy code to wrap the method calls.
>>
>> This is only one case where it works to advantage.  I take this for
>> granted with Java, would this always have to be something done outside
>> the D language?  I.e. generate source code and then have the compiler
>> compile it for me?  (Not very dynamic, huh?)
>>
>> Of course, one wonders about the possibilities of embedding scripting
>> languages in a D program for just this type of thing?
> 
> 
> I had some ideas concerning a macro extension based on the one 
> implemented in Nemerle. <http://nemerle.org>  Basically, a 'macro' 
> recieves a piece of syntax from the document, and returns a new AST node 
> which is injected in the macro's place.  (about two thirds of Nemerle's 
> 'core' syntax is implemented with these things)
> 
> Along with a hundred other potentially interesting things, such a 
> mechanism would make it pretty simple to write a decorator which 
> iterates over the contents of a class and inserts extra reflection 
> information.  (or generating language bindings)
> 
> For the moment, though, it remains little more than the frantic 
> scribblings of a madman. :)
> 
> On the upside, D is pretty easy to parse: it wouldn't be hard to write a 
> little Python script that scans the source and generates more source 
> from it.
> 
>  -- andy


Yeah, I actually wrote a little app in D that parsed out an input file 
and let you do special macro templates that looked something like this:

macro SimpleFunc(type, funct, ret)
{
	$type $funct()
	{
		return $ret;
	}
}

SimpleFunc@(int, five, 5);

void Main()
{
	printf("%d\n", five());
}

I had also done some built-in bits to automatically execute a macro 
automatically passing it things such as the members of a class... sort 
of a macro loop deal.

if you want, I can look for it.  It might be a start, if nothing else :)

Deja
July 27, 2004
Re: Dynamic Proxies, dare anyone get their hopes up?
Berin Loritsch wrote:

> One of the nicer features of working on Java and other byte-code
> derived languages is the concept of generative programming.  One
> of the most common ideas is the dynamic proxy.  The dynamic proxy
> allows someone to create a class that implements one or more interfaces
> to implement some feature on a class that is already implemented.
> 
> One of the best examples of where it really works to the developer's
> benefit is making it easy to generate a stub proxy.  For example, if
> one wants to connect to a web service through SOAP, the dynamic proxy
> will use the interface to the web service, with the SOAP engine
> generating proxy code to wrap the method calls.
> 
> This is only one case where it works to advantage.  I take this for
> granted with Java, would this always have to be something done outside
> the D language?  I.e. generate source code and then have the compiler
> compile it for me?  (Not very dynamic, huh?)
> 
> Of course, one wonders about the possibilities of embedding scripting
> languages in a D program for just this type of thing?

I'm not sure if this is totally what you're looking for, but pragma is 
solving some of the same issues (I think)

http://www.dsource.org/forums/viewtopic.php?t=211

or

http://www.dsource.org/forums/viewforum.php?f=28

or

http://www.dsource.org/projects/dsp (and browse the SVN repository)

BA
Top | Discussion index | About this forum | D home