Fully dynamic d by opDotExp overloading

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Fri Apr 17 12:38:53 PDT 2009


Steven Schveighoffer wrote:
> On Fri, 17 Apr 2009 15:08:12 -0400, Andrei Alexandrescu 
> <SeeWebsiteForEmail at erdani.org> wrote:
> I guess I don't mind the dynamic lookup of methods, but I really don't 
> like the proposal to make it look exactly like a statically typed call.  
> To "hide" the fact that you are doing a dynamic lookup makes me worry 
> about losing the invariants that I come to enjoy with statically typed 
> methods, that is, if I see x.method(a, b, c), it means that the compiler 
> has checked that I called that method correctly with the correctly typed 
> information.

Yah, but that feeling of losing control often marks a paradigm shift (I 
hate that term, but incidentally it's exactly what I mean here; I guess 
there is a legit use for it after all). Some people were completely 
pissed that ++i does not necessarily mean one machine operation, but 
instead an arbitrary function call. Then STL came and knocked 
everybody's socks off.

> I use C#'s runtime introspection all the time, and it makes for some 
> really awesome code (things I wish D could do), but I still have to do 
> things like
> 
> Type[] argTypes = ...;
> object[] args = ...;
> x.GetType().GetMethod("myMethod", argTypes).Invoke(x, args);
> 
> To have that simply cut down to:
> 
> x.myMethod(a, b, c);
> 
> is a nifty experiment, but now I lost all ability to know how the 
> compiler is interpreting that.  I bet D can do a much better job at 
> runtime type information than C# due to the template system being so 
> powerful, but I still want to know that I'm dynamically doing something 
> versus statically.

I don't think you need to worry. Such a style would belong to a handful 
of types, e.g. Any. It's not a big deal that what you're doing with a 
value depends on its type.

> Something like:
> 
> void foo(object x)
> {
>    x.invoke("myMethod", a, b, c);
> }
> 
> where invoke is some method that uses the classinfo of x to look up the 
> method would be freaking awesome ;)

But that doesn't quite unify things.


Andrei



More information about the Digitalmars-d mailing list