Tuesday 10 February 2004 — This is over 20 years old. Be careful.
Cog is a code generation tool I wrote to solve some problems at work. It’s based on embedding Python in source files to generate code (we use it to generate C++, for example).
I’m really happy with the way Cog turned out. Some would say that Cog isn’t a code generation tool at all, but just a file munger that can be used for code generation. They would be right, Cog does much less than most “code generators”. But it was written to munge files in just the way you need to when generating code. Cog only does one thing, and it does it well: it executes chunks of Python it finds in text files, capturing the output and writing it into the file alongside the original code.
Download it, try it out, and let me know what you think.
For more about code generation in general, try:
- Dave Thomas interviewed about code generation. Dave Thomas is one of the Pragmatic Programmers, and I find I agree with him almost universally. He forbids putting the output of code generators under source control, I encourage it. We agree that the output should never be edited.
- The Code Generation page on the c2 wiki. As will happen with a wiki, this fractures off in many directions, with many different viewpoints, both for and against code generation.
Comments
http://www.alcyone.com/software/empy/
http://www.students.tut.fi/~vainio24/pywiz/
Add a comment: