Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
509 views
in Technique[技术] by (71.8m points)

language agnostic - What's the use of metaprogramming?

I've read:

and I confess some confusion at the purpose behind metaprogramming/code generation.

Does anyone have a concrete example of where they use metaprogramming/code generation? Even better would be an accompanying explanation of why it was better than an alternative.

edit: Would Thistle be considered metaprogramming?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Imagine a guy who builds cars. Say it's the same thing as using a computer.
At some point he realizes he's always doing the same thing, more or less.
So he builds factories to build cars, and it's much better. He's now programming !
Nevertheless, once again, at some point, he realizes he's always doing the same thing, to some extent.
Now he decides to build factories that build factories that build cars. That's metaprogramming.

Metaprogramming is immensely powerful, but one glitch in the system makes all advantages turn into monster difficulties. So master it and use it... Or stay away !


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...