Create dynamic functions with Macro

If you have an explosion of arguments, it’s probably a sign that you need better abstractions.

Abstraction and software design and refactoring is hard, and I can’t give you a magic formula in a few words that will solve everything — there are whole books written about this. But using macros to automate cut-and-paste code is a last resort, rarely needed for this purpose, and certainly not the first thing you should reach for.

One reason is that macros have to be designed very carefully to avoid subtle fragilities arising from scope. Another is that macros usually have less information to work with than ordinary functions — macros only know how things are “spelled”, whereas functions know types and values. See also the thread: How to warn new users away from metaprogramming

2 Likes