I can understand templating languages (e.g. jinja2) which add dynamic logic using a high level language (e.g. Python) to a dumb markdown language (e.g. HTML), but I don't see the need to generate code for another high level language.
I can understand templating languages (e.g. jinja2) which add dynamic logic using a high level language (e.g. Python) to a dumb markdown language (e.g. HTML), but I don't see the need to generate code for another high level language.
Markdown files on GitHub for example don't support any form of templating language - but Cog is a template language which can be hidden away in <!-- comments --> in your Markdown, and then executed using a separate command:
cog -r README.md
So it's a templating language for files that don't usually support templating languages, but that do support comments.- documentation from source-code files, some CLI frameworks are offering this (eg. oclif[0])
- types from schema files, and schemas from types (eg. quicktype[1])
- API clients and servers from specifications (eg. openapi-generator[2])
...these are all repetitive tasks that can be automated.
That being said, I wouldn't personally generate it in the build step, but rather introduce an additional generate step for it and sync the generated output with the VCS of choice. I recently wrote about it a bit here[3].
[0]: https://github.com/oclif/oclif#oclif-readme
[1]: https://app.quicktype.io/
[2]: https://github.com/OpenAPITools/openapi-generator
[3]: https://blog.whilenot.dev/posts/typescript-source-code-gener...
(Lisps, OTOH, have macro capabilities that do the same thing elegantly behind the scenes.)
If you statically generate a bunch of methods from a schema, it’s very easy to just read the output source, and the JIT is much happier with the code.
Code generation is also nice for things like generating Typescript definitions for your frontend to interact with a backend API. The value is partly derived from Python being a language with great introspection tools, so the codegen code itself is easy.
It's not so much that this is the principled way of doing things, but it might be a way that is good enough and gets you where you need to be, in a slightly reproducible fashion.
i had python code that generated another python code which then generated C (and C++) for wrapping CORBA.. 20 years ago.
Like 1000 LOC generated 5k that generated about 100K C.. No way to make that by hand - and keep it consistent.. Unless, one has to employ large number of people for the sake of it..
We use something like this (our own version, not in Python) for the above cases. We generate VHDL and C. It's incredibly powerful.