What exactly is metaprogramming?

后端 未结 7 2292
醉话见心
醉话见心 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:55

    Metaprogramming is the writing of computer programs that write or manipulate other programs (or themselves) as their data, or that do part of the work at runtime that would otherwise be done at compile time. In many cases, this allows programmers to get more done in the same amount of time as they would take to write all the code manually, or it gives programs greater flexibility to efficiently handle new situations without recompilation. (Source.)

    Basically, it's writing code that outputs more code, which is run to accomplish some goal. This is usually done either within the same language (using javascript to create a javascript string, then eval it) or to emit another language (using .NET to create a windows batch file).

提交回复
热议问题