Walter: extend existing classes with new methods?

Bill Baxter wbaxter at gmail.com
Wed Aug 30 19:26:28 PDT 2006


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.

That said, it might be nice for some aspects of dynamic typing to be 
built in to the language.  From what I gather, that's one of the 
strengths of Objective-C, and what makes it a good language for writing 
GUIs.

So the first step would be to ask if D is going to gain support for 
basic dynamic method calling, THEN you can ask the question of whether 
or not adding dynamic methods to existing classes will be allowed.  But 
I guess if you have dynamic methods, then adding them to classes a la 
Smalltalk is really not a big deal.  Just a matter of putting another 
pointer in the class's dynamic method dict.

--bb



More information about the Digitalmars-d mailing list