Monday, September 17, 2007

Metaprogramming

I was sick last week, made me turn the hours around. So another sleepless night brings me back from bed, into my chair in front of the computer. What is haunting me the most right now it the answers to my friend Johans riddles. And I stumble upon a word I didn’t recognize – Metaprogramming. So I use Wikipedia (as you may have noticed) as my major tool to understand all of these words and concepts that I have never seen.

http://en.wikipedia.org/wiki/Metaprogramming - Read it!

I soon discover that Metaprogramming is a fancy word for self modifying code, code generators, translators, macros. You name it, anything that has anything to do with generating new code. So I grasp the concept. I read on anyway because the article is interesting and might shed new exciting light upon the subject, mainly because I’m into code generators and O/R-mapping.

Then I read something that is very intriguing;

“Not all metaprogramming involves generative programming. If programs are modifiable at runtime (such as in Lisp, Python, Smalltalk, Ruby, PHP, Perl, and Tcl), then techniques can be used to perform metaprogramming without actually generating source code.”

I don’t understand this text. What does it mean? It sounds very intriguing, but I cannot grasp the concept. I read it over and over and I finally level with it, and realize that this is what I used to do with macros back in the days of assembler and C++ programming. Only now, the language itself supports generating itself in runtime. Whilst macros are evaluated at compile time or even pre compile. So I read on, the text talks about compilers being metaprogramming tools. Then, the second last sentence hits me hard;

“Having the programming language itself as a first-class data type (as in Lisp) is also very useful.”

Oh my God!

And a whole world of possibilities unravels before my inner vision..

No comments: