Well, here's a timely screed about macros and why they make sense - to which I can only say, "Yeah!"
Which brings me to discussion (again, and we'll keep discussing this until it comes out right!) of macros and code generation.
Let us imagine a system of articles and books that describe a codebase. Some of the codebase may be maintained outside this system; some of it within, because the articles include some literate programming tools that can generate sections of code. (This way the system can be used to start analyzing an existing codebase and slowly grow to encompass all of it, as needed.)
An article is equivalent to a book section, that is, a book consists of a hierarchical organization of multiple articles, presumably related. An article may still have hierarchical structure within it, though, because sometimes you just need that for clarity.
In general, though, a single article addresses a single "thing". That topic could be a feature or a specific function, or it could be a change request touching many different parts of the system. Ideally the maintenance of a complex system would thus have a narrative made up of multiple articles explaining the thinking at each stage.
OK. So in that context, let's assume that some of our literate programming-type tools include arbitrary macros that can be reused. (Literate programming can be seen as writing a number of single-use macros, so generalization of that to reusable macros is no great leap.) Some languages are easier to macro-ize than others, of course: we have to parse things to make truly effective use of macros without leaving the native syntax. But by extending the native syntax with a template language, of course (as we do in literate programming, actually) we can build macros for any language. The key is the code generation, you see.
It might be a good idea, though, if particularly questionable or novel macros were to be given a kind of "half-way existence", where the macro as well as its expansion are shown in the presentation. Maintenance then has a template or macro to work with, but the full code is shown for clarity. There are plenty of instances where that makes a lot of sense to me.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment