Is metaprogramming useful?
Craig Black
cblack at ara.com
Mon Nov 27 07:13:49 PST 2006
Good response. This info should be on a publicly available FAQ.
With respect to compile time regex, the full power of this will not be
available until D can better optimize the code that is generated. I've
never seen any benchmark comparisons with the run-time regexes and I assume
its because it doesn't end up being much faster. (Correct me if I'm wrong
here.) If this is the case, it is not because metaprogramming is not
useful, it is because DMD doesn't do certain optimizations yet.
That said, there will always be a trade off between run-time and
compile-time performance when dealing with metaprogramming. In a systems
programming language, usually run-time performance is more important. Thus
metaprogramming definitely has merit in a language like D. However, if you
want faster compiles, use run-time code.
-Craig
"Sean Kelly" <sean at f4.ca> wrote in message
news:ekerg7$32b$1 at digitaldaemon.com...
> Frank Benoit (keinfarbton) wrote:
>>
>> 1.) Is metaprogramming really useful or only kind of hype?
>
> In-language code generation has an advantage over using a standalone
> preprocessor to perform the same task. And generated code has the
> potential to contain fewer bugs than hand-written code, as well as reduce
> coding time for a project. Finally, template code in general combined
> with common optimizer techniques can result in extremely fast code because
> it is essentially equivalent to hand-optimized code in many cases. How
> fast? Bjarne did a presentation at SDWest regarding some real-world
> applications where C++ was shown to outperform hand-tuned C and even
> FORTRAN by an order of magnitude for numeric calculations, and the reason
> was entirely attributed to the extensive use of template code. Granted,
> metaprogramming is but a subset of template programming, but sometimes the
> line between the two is fairly blurry.
>
>> 2.) Are there examples where a metaprogramming solution is the best way
>> to solve it?
>
> Blitz++ uses metaprogramming to gain a measurable speed increase in
> executable code. But I think the real power of metaprogramming is
> contingent upon how well it integrates with the run-time language. In
> C++, this integration is really fairly poor. In D it's much better, but
> could still be improved. The ideal situation would be if the syntax of a
> normal function call could be optimized using metaprogramming if some of
> the arguments were constants, rather than requiring a special syntax to do
> so. Two fairly decent examples of metaprogramming in C++ are expression
> templates and lambda functions (Boost).
>
>
> Sean
More information about the Digitalmars-d
mailing list