An Introduction to Metaprogramming


"An Introduction to Metaprogramming" is an article written by, one of the best professors I've had, and yes, I am a sentimental but is my last course with him, the professor Ariel Ortiz.
First of all, metaprogramming basically, writing metaprograms, not so explicative.

Create a metaprogram will generate another program or just part of it but without the effort of doing more than the indispensable amount of code.

I liked the example about the woman who was supposed to write something, and she did it but not in the way expected, so she write a program for write the program she must do.

This pattern is really useful when a developer want to reach an specific solution using one specific language to write a program which intention is generate another program, this can also be used to write the same code in another language.

This practice will help to eliminate or/and reduce a tedious or error-prone programming task, as said in the article, plus the time optimization while coding.

How to do it?

Well I am not going to say it is easy, because that probably is not all true, but it is possible just by having enough knowledge of the programming language that will be generated for the metaprogram.

Metaprogramming also allows the possibility to generate source code and execute it in real time, this facility is provided by the function eval, in some languages like Lisp, Perl, Ruby, Python and JavaScript. Another advantage about eval is the possibility of modifying programs during Runtime.

But eval, like everything have its disadvantages, it can be insecure. That is why exist another alternatives as quines, quines are defined as a program that generates a copy of its own source code/text as an output.

I liked the topic, it gives a different perspective about the programming languages.


Comentarios

Entradas populares de este blog

Is Design Dead?

Software Architecture

Understanding the SOLID Principles