What exactly is metaprogramming?

后端 未结 7 2294
醉话见心
醉话见心 2020-12-12 09:00

I was reading an article on TheServerSide on ployglot programming on the Java platform. Some comments in the article refer to metaprogramming as the ability to generate code

7条回答
  •  伪装坚强ぢ
    2020-12-12 09:48

    Metaprogramming is writing a program which outputs another program. This is something languages like Lisp are really good at. It is much easier to do in a language that supports real macros (not C++ macros, but rather ones that can manipulate the code they output) such as Ruby, Lisp, Scheme, etc. than in a language like Java.

    One implementation is to create a "domain specific language" which is a way of enhancing a programming language to accomplish a specific task. It can be incredibly powerful if done correctly. Ruby on Rails is a good example of this sort of programming.

    If you interested in exploring this method, check out the Structure and Interpretation of Computer Programs which is one of the seminal books covering the subject.

提交回复
热议问题