Metaprogramming, is it a solution?
Why Metaprogramming?
Benefits:
- We could do the computation at runtime instead of compile time. By doing as much work as possible before the resulting program starts, we get faster programs. The result of the computation can interact more deeply with the target language. This is possible because the actions are processed during grammar compilation and passed to the target C/C++ compiler.
- Once the metaprogram is written, its benefits of convenience can be spread across a community of other programmers. (For a metaprogram that will only be used once, different alternatives might be more efficient)
- Regardless of how many times it’s used, a metaprogram enables its user to write more expressive code, because the result can be specified in a form that corresponds to programmer’s mental model.
- The resulting program is more likely to be correct and maintanable.
Why C++ Metaprogramming?
- User can enter the domain language directly, without learning a foreign syntax or interrupting the flow of the code
- Interfacing metaprograms with other code, especially other metaprograms, becomes much smoother
- No additional build step is required
- Metaprogramming moves the computation required for expressivity and correctness from runtime to compile time
When Metaprogramming?
- The code needs to be expressed in terms of the abstractions of the problem domain
- When it is needed to write a great deal of boilerplate implementation code
- When it is needed to take the advantage of valuable properties of generic programming in C++ such as static type checking and behaviour customization, without loss of effiency
- The code needs to be written in C++ language, without an external tool or custom source code generator
[summarized from this book]
Conclusion:
- For my case, I don’t have to understand about metaprogramming to utilize the templates (which is good 😉 )
- This writing about metaprogramming really helps me to move on without worrying about less prior tasks. Thx buddy 😉
tetangga sebelah 3:59 pm on July 18, 2008 Permalink |
tetangga sebelah 4:05 pm on July 18, 2008 Permalink |
chikaradirghsa 6:07 pm on July 18, 2008 Permalink |
@tetangga sebelah: =))
lagiiiiii lagiiiiiiii!!!
tetangga sebelah 11:46 am on July 19, 2008 Permalink |
PlokmasterBloggingTools 1:37 pm on July 19, 2008 Permalink |
Hello… nice blog you got here… I have a new developed software for you… and I have provided a demo… visit my blog now!
kyaw kyaw naing GEORGE 8:17 pm on December 28, 2008 Permalink |
I guess the strong point of Metaprogramming is conciness and the weak point of Metaprogramming is conciness, too.
Just as when a code is small/short, it aids our understanding,
such short code can cause us to scratch our heads in frustration.
As long as the techniques we use are understandable, i think it wil be ok.