Walter: extend existing classes with new methods?

Marcio mqmnews321 at sglebs.com
Sun Sep 3 12:00:19 PDT 2006


Bill Baxter wrote:
> Marcio wrote:
>> Walter,
>>
>>    Do you plan to add the ability of adding methods to an existing 
>> class, from another module?
>>
>>    This ties to the issues raised at 
>> http://www.cs.princeton.edu/~dpw/popl/06/Tim-POPL.ppt and the fact 
>> that some languages/systems have had this capability for years 
>> (Smalltalk, for example, and more recently Ruby) with very beneficial 
>> results.
>>
> 
> Smalltalk and Ruby are both dynamically typed languages.  D is 
> statically typed -- that is the type of everything must be known at 
> compile-time, and in particular what methods are present must be known. 
>    AFIK, in D, like in C++, someobject.foo() either fails to compile, or 
> it successully calls foo() at runtime.  There is no runtime check to see 
> if the method exists or not before calling it.  What you're asking for 
> is a really big fundamental change to what D is.


No, I am asking for extending at compile-time. Example: You provide me 
with a library written in D, with full source, and my app can add 
methods to some of your classes. Then I compile the full source.

This is quite doable, even in D.

Adding methods at runtime is an issue if you allow plugins to be loaded 
from DLLs. If these plugins can add not only classes but also add 
methods to existing classes, then you need the functionality at runtime.

I am being modest in my request. Compile-time extension would be 
straightforward and very useful.

marcio



More information about the Digitalmars-d mailing list