Get the name of a function and the parameters?

Jarrett Billingsley jarrett.billingsley at gmail.com
Wed Apr 29 07:24:13 PDT 2009


On Wed, Apr 29, 2009 at 2:52 AM, Georg Wrede <georg.wrede at iki.fi> wrote:
> Jarrett Billingsley wrote:
>
>> Don't you love it?  "Most C++ template features are discovered."  So are
>> D's.
>
> Well, one could say that this is the very definition of a well working
> metaprogramming system. After all, the whole idea of templates is to let the
> programmer invent new ways to use the lanaguage, the compiler, and the
> template system.

That's not.. really at all what the issue is here.  The issue is more
that most of the metaprogramming features in D are completely
unspecified, and when we discover that something works, it's hard to
tell if it's _supposed_ to be that way or if we're taking advantage of
some weird bug in the compiler.  Show me a page that documents
.stringof!  Thought not.

As some other examples, did you know it's possible to get the names of
the fields of a struct type (and probably a class type too with a
similar method)?  It only works under extremely contrived
circumstances, using .stringof, and parsing out the names yourself
from a very horrible-looking string.  It's also possible to get the
name of a local variable by instantiating a template in a local scope
and parsing a horrid .mangleof string.  You can also determine some
(not *all*, but some) interesting properties of functions and methods
- things like final, static, abstract - by creating dummy inherited
classes and attempting to do awful things to them.

Metaprogramming should be _well-specified_ and _orthogonal_.  I agree
with you that the _possibilities_ of metaprogramming should be almost
boundless and should allow you to come up with your own DSLs.  But the
compiler shouldn't hold information about your program "ransom" and
make you work so goddamn hard to get at it.  I should be able to just
write, I don't know, __traits(parameterNames, f) and get a tuple of
parameter names!  I'm tired of puzzling out information that should be
directly available!


More information about the Digitalmars-d-learn mailing list