Literate programming is generative programming

Literate programming can directly enable generative programming by acting as a glue code. The original TexBook is itself an example of this as it is written in Pascal but finally translated to C. While noweb added pipes to literate programming and nuweb, funnelweb added support for cpp style macros, in wheel you have can make complete use of Python, thanks to cog. With cog you can do ad-hoc text generation and macro preprocessing using templates. Generative programming using a preprocessor like cog can be used as an alternative to reader-macros. These experiments have been tried and tested in Plannr, which is now written in a lisp / hylang dialect to improve code readability for the end-user.

The preprocessing approach taking by javascript and the modern eco system also fits nicely with literate programming. Simply put you don’t need webpack and babel if you are effectively using literate programming. This approach was borrowed from litpro. A particularly useful case of generative programming is state machine generation from metadata and automatic test code generation.

By using cog effectively you can stop using cpp and implement objects and templates on top of C, just like the original cfront compiler. A project exploring this approach on enhancing C has been created here.