Fully dynamic d by opDotExp overloading

Nick Sabalausky a at a.a
Fri Apr 17 12:45:43 PDT 2009


"Andrei Alexandrescu" <SeeWebsiteForEmail at erdani.org> wrote in message 
news:gsak2p$1s8a$1 at digitalmars.com...
>
> I think there's merit in binding via strings. It makes for very flexible 
> code that is future-proof, dynamic-linking-friendly, and hot-swappable 
> without recompiling (e.g. you don't need to recompile because you now 
> implement an interface etc.) Reflection is very useful as well.
>
> I think D can and should allow string lookup for its methods. It's a 
> low-complexity proposition that adds a very interesting tool to D's 
> arsenal.
>

That's a separate issue. I absolutely agree with the usefulness of being 
able to invoke static methods via a string identifier at runtime. But I 
think opDotExp is an extremely flawed way to do it. A much better way would 
be through a reflection mechanism:

class Foo
{
    void bar() {}
}

auto foo = new Foo();
traits(foo).func("bar").invoke();

That way, you can have the benefits of runtime-string-identifier-invocation 
(and have it on *every* class/method), but without completely loosing 
compile-time checking on the members of every class which is capable of 
using it.

> If anything, this agreed-fest shows that the rift between static typing 
> and dynamic typing is alive and well. I've seen many discussions in which 
> people were mystified how anyone gets anything done in a statically-typed 
> OO language.

...Doesn't necessarily mean both sides have valid points. Just that there's 
disagreement. Outside of diplomacy, it doesn't make any sense to agree with 
something you disagree with, or disagree with something you agree with, just 
for the sake a closing a rift. Better to just continue debating the issues 
with logical arguments. If nothing gets accomplished, well ok, fine, but so 
what? That's a lot better than coming to hasty-but-wrong agreement just for 
the sake of agreement.

I guess what I'm saying is, people coming to an agreement is all fine and 
dandy, but the most important thing is to arrive at the *correct* agreement. 
If one group of people insist that "2+2=0" and another group insists that 
"2+2=10", then it's far better to keep analyzing and debating until "2+2=4" 
is discovered and proven than to say "let's all be happy!" and hastily agree 
that "2+2=5". Again, outside of diplomacy, people disagreeing is not the 
real problem, the real problem is that the best answer either hasn't been 
found or hasn't been unquestionably shown to be best. 





More information about the Digitalmars-d mailing list