Is metaprogramming useful?
Georg Wrede
georg.wrede at nospam.org
Wed Nov 29 15:27:36 PST 2006
renoX wrote:
> Back on the subject of metaprogamming, one thing which makes me cautious about
> metaprogramming is debugging: when there is a problem debugging generated code is
> a nightmare usually..
It's not metaprogramming itself, it's the bad implementations that make
it hard.
If we had Perfect Metaprogramming(TM) in D, then I could do the following:
I'm coding some stuff and I notice that what I'd really want
is a new keyword, "unless", that would make it so much easier
for me to write this application clearly. I decide to create it.
I want to use it like this
unless (fullMoonTonight) { doRegularStuff() }
So, to create such a thing in D, I'd write something like
define("unless", "(", BooleanExpression, ")", BlockStatement)
{
if(!BooleanExpression) BlockSTatement;
}
Now, if I'd made errors in writing the meta code, then the compiler
would error me, of course. No biggie. And since the D compiler would
understand what's going on (as opposed to the C preprosessor or
compiler), the error messages would be what we're used to in D.
Later, when I actually use the "unless" construct, again the error
messages would be normal because D now understands what "unless" is all
about.
---
People say GC has to be slow, but that is mostly because it used to only
exist in languages that were slow to begin with (and badly implemented).
The same thing with metaprogramming. C++ has given it such a bad rep,
it'll take years before folks learn away from their fears.
More information about the Digitalmars-d
mailing list