Question

I found that some tool such as Noweb doesn't support macro. I want to know what are the advantages and disadvantages of macro in literate programming?

Was it helpful?

Solution

I'll assume that by "macro" you mean having the LP tool do "macro-substitution" like the C preprocessor and most assemblers.

Macro substitution is "syntactic sugar". It's a way to write a single symbol that stands for lots of similar details. Hence the term "macro": It was "macro-programming", writing at a higher level of abstraction.

This is what we did in the olden days when we didn't have object-oriented programming to provide easily-accessible layers of abstraction.

It was -- technically -- possible to have layers of abstraction and macro-style programming in C using just function calls. The pre-processor "macro" programming isn't necessary. For example, we used to define inline functions as a preprocessor "macro" to hand-optimize our code. That's because the C compiler didn't optimize well in the early days.

Now that we have OO programming, the macro capabilities of more primitive programming languages aren't needed.

The Literate Programming macro feature was used in non-OO languages (like C and Pascal) to create class-like capabilities, and inheritance-like capabilities at the LP level.

There's no point in that. Just define proper classes and use proper inheritance.

OTHER TIPS

I wrote 2 different LP tools: TCLP - does not support macros: http://code.google.com/p/tclp amd NanoLP, with very flexible macros supporting: http://code.google.com/p/nano-lp.

And when I had writing TCLP, my ideas about macros was - it's bad because it destroys program structure, something like another macro system - you can thinking about it like about parallel macro-system in C language. C macroses hides real code - they are not real function calling, but hides (like placeholders!) real code and LP-macros are parallel way to hide code. This is disadventeges.

But if you write good LP macros, readable and understandable, then no problems to use they, so I included flex macros system (with plaeholders, importing, variables dictionaries...) into my next tool - NanoLP.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top