How you would define metaprogramming?

Started by
25 comments, last by Madster 18 years, 3 months ago
Am I correct in thinking that metaprogramming is "programming of programming", such as writing program that generates code, and the like? (or creating templates that nontrivially generate code). So the quine is simple, agreed upon "helloworld-ish" example of metaprogram. Just were discussing it in russian and have feeling that there's some language barrier... either i or other side simply doesn't understand what "meta" as in "meta-programming" means. (they defined metaprogramming as programming in "other language", whatever it means (meta-language? lol)...)
Advertisement
You are correct, although I would say 'Programming about programming'.

One could define a program in a self defined language and then use some sort
of compiler to create the program in another language, say C or Java.

I have in the past used XML and XSLT to transform my XML to C# code. Just search for metaprogramming or try something out yourself.
Typical examples of metaprogramming include C preprocessor directives, Flex definitions, YACC grammars, and just about anything using the word "macro".
Quote:Original post by Dmytry
Am I correct in thinking that metaprogramming is "programming of programming", such as writing program that generates code, and the like? (or creating templates that nontrivially generate code).


Something like that, code generation is a specific instance of metaprogramming so there is more to it than simply generating code, you might want to read this. It can be done at compile-time, runtime, mix of both, it can be stagged as in a number of stages/levels occuring a different periods of time.

Refraction & Reflection is a form of metaprogramming since you are inspecting, querying, and/or modifying the actual program at runtime and/or compile-time.

Quote:Original post by Dmytry
So the quine is simple, agreed upon "helloworld-ish" example of metaprogram.


Not really although i guess it is some form of metaprogramming.

Quote:Original post by Dmytry
Just were discussing it in russian and have feeling that there's some language barrier... either i or other side simply doesn't understand what "meta" as in "meta-programming" means. (they defined metaprogramming as programming in "other language", whatever it means (meta-language? lol)...)


Yes a meta-language, it is higher level than the language it inspects/queries/manipulates, you write metaprograms with metadata, metafunctions, etc, etc.

The meta-language doesn't necessarily have to be different or completely different from the language in terms of syntax altough it may appear to look different when writing metaprograms.

[Edited by - snk_kid on December 29, 2005 11:45:30 AM]
Thanks.

That basically confirms my definition. My definition is quite broad, not just explicit code generation of course, but almost any sort of nontrivial programming the programming. Sorta processing/creating the program programmatically. I meant that other side's definition requirs "other language" (very vaguely defined) and is much narrower (and IMO narrower in C++ - specific way).
Dmytry,
The person you are arguing with is sort-of right about using another language for metaprogramming. It's not a reuirement, but most examples of metaprogramming are in a meta-language. C++'s templates form a language quite seperate from C++. The main flow control is pattern matching on template arguments, there's no iteration (only recursion), etc...

The C Preprocessor is clearly a seperate language.

LISP's macros are the only example I can think of where the meta-language is the same as the programming language.

-Alex
I always assumed the origin of the term was meta-data in databases. Meta-data is your data about the data, basically the information stored in the system tables. A simple example of using meta-data in a decision support system is allowing a user to select tables to use in a query, then listing the union of the columns of the tables to let them select sorted order, the result set and selection criteria, then using the intersection of the index fields to build the where clause.

So to me I would include enum and typedefs in templated classes as metaprogramming. numeric_limits would be a prime example of supplying meta-data for a data type. Then using that information generate appropriate code would be meta-programming. Mostly, as I see the term used, it's basically writing code executed by the compiler. Examples being calculating n! or unwinding a loop. I assume that's the main use of the term because at that stage meta-programming is about all you are doing. As I view the term it would include many parts of the STL. Not the algorithms themselves, but much of what makes them work, i.e. iterators, traits, predicates, function objects, etc.
Keys to success: Ability, ambition and opportunity.
Quote:Original post by cypherx
Dmytry,
The person you are arguing with is sort-of right about using another language for metaprogramming. It's not a reuirement, but most examples of metaprogramming are in a meta-language. C++'s templates form a language quite seperate from C++. The main flow control is pattern matching on template arguments, there's no iteration (only recursion), etc...

The C Preprocessor is clearly a seperate language.

LISP's macros are the only example I can think of where the meta-language is the same as the programming language.

-Alex


I argee about him being sort of right(i.e. not entirely wrong) (my definition mostly includes his), it's the requiring another language that was disputed... i.e. we argued if that's metaprogramming or not if is not about another language.
as about another example when it is same language, consider code generator written in say C++ that produces C++ code. It's just that definition requiring "other language" is really vague (C++ templates it is part of C++ too)

[Edited by - Dmytry on December 29, 2005 11:05:22 AM]
I think that functional programming languages (not only lisp) are examples of languages that feature metaprogramming.
@Dmytry: As you are really smart when it comes to mathematics, you may find interesting comparing metaprogramming with metalanguages in mathematic and philosophy (ie Russel or Wittgenstein works).
I don't know much about it myself, but it should be a quite interesting topic (paradoxes and logical fallacies).
Are we not all missing a great point here? The great deveoplers of the past developed "meta" languages (templates, lisp, even xml etc.) so we could "describe" language..nouns not verbs. BUT it exists for us to use, full stop.

I don't think they were great philosophers but great scientists. The philosophy of language is far older than the computer age and meta langauges have existed as long as any language...aristole says that language descibes the soul and we all use it's many different and varied varities.

Lets thank all the wonderful people that came before us, but lets just write some good stuff, cross our fingers and get on with it.

PS. Happy New Year...xxxooo
Gary.Goodbye, and thanks for all the fish.

This topic is closed to new replies.

Advertisement