10

How often do you or have you seen meta-programming be used in projects? In uni I've never seen this be applied, but I've seen this on my previous job (when I saw it I was blown away of how effective it was).

But how common is it? Is it used all the time, or just occasionally?

gablin
  • 17,525

4 Answers4

5

If you consider reflection a kind of meta-programming, it is relatively common. For some people even generic programming (templates and generics) is a form of meta-programming, so that's even more common.

In my opinion, however, meta-programming is something more complex, that involves actual code generation, and therefore quite uncommon, even in scripting languages.

Wizard79
  • 7,337
  • 2
  • 43
  • 76
3

I think it depends strongly on what language you use. Common Lisp people probably make a fair use of it - the Meta-Object Protocol allows for neat things transparent/orthogonal persistence, for instance - and Smalltalkers use it frequently.

Frank Shearar
  • 16,751
2

It tends to show up commonly and consistently in Common Lisp projects. Check out OnLisp and Let Over Lambda for some explanation/insight.

If you're just after examples (and know CL), check out the Antiweb repository; there's a good deal of meta-programming going on under the covers.

Inaimathi
  • 4,874
1

For the past two years the first bit of programming on a new task has almost always been writing code to write code. There's a ton of boilerplate associated with interactions with a database that can be simplified down to automatic script generation. Think of things where you need to query 3 tables to form an object or some such. Why write it yourself if there's 10 of these things that might change in the future?

wheaties
  • 3,564