jeudi 15 juin 2017

Differences in Macros and Reflection in Meta-Programming

I'm currently studying about Meta-Programming. I guess Ruby on Rails uses meta-programming heavily. Here is what I understand so far.

  • Macros: Happens in compile-time, uses code to generate code (i.e. Rails uses attr_reader to automatically set up getters)
  • Reflection: Happens in run-time (I read reflection uses it's own language as a meta-language, but not sure what this means)
  • Meta-Programming uses a program as a data type to generate code; Macros and Reflection are techniques of Meta-Programming in some sense.

I have total 3 questions.

  1. I am having hard time to understand what Reflection is.
  2. What's the difference between Macros and Reflection
  3. Whether I can see Macros and Reflection as a subset of Meta-Programming since the definition of Macros and Meta-Programming almost seems identical to me.

If you can explain this in using Ruby/Rails, that would help me a lot. Thanks!





Aucun commentaire:

Enregistrer un commentaire