Is macros support in a programming language considered harmful

clanguage-designlispmacros

The first abuse that comes to my mind in C is:

#define if while 

But at the same time it is extremely handy and powerful when used correctly.

Something similar happens with Common Lisp macros.

Why doesn't all the programming languages support macros like this and what are the alternatives?

Is it they are considered harmful?

Best Answer

I am of the opinion that if a language has macros, they should be a well planned out and integral part of the language and not of the compiler.

Example, Lisp's macro system is a very powerful integrated language feature and is subject to all the rules and regulations of Lisp itself.

Counter-example, C/C++ macro system is separate from the language and built into the compiler. The result is that you are not limited to the constraints of your language and can create invalid code and redefine language specific keywords.

At the end of the day, there are several languages that have no macro feature--but those fatures are not missed as much. It all depends on how expressive a language is, and whether it has alternative approaches to meta-programming. Meta-programming is just a way of ensuring that when you do X, X is done the same way all throughout the application.

Related Topic