[Haskell-cafe] Code that writes code

Richard O'Keefe ok at cs.otago.ac.nz
Tue Aug 24 17:51:20 EDT 2010

On Aug 22, 2010, at 7:34 PM, Jesse Schalken wrote:

> I would also like to strongly discourage code generators.

I've used ad hoc code generators a lot, and never had
reason to regret it.

The key point is that ALL maintenance of the generated code
must be done by maintaining the generator and its input,
NOT by patching the output.

> Every software project which I've worked on that used a code generator
> turned into a nightmare, because when we find we need to change
> something about the generator's output, all the already generated code
> has to be updated manually while at the same time maintaining all of the
> unique modifications that have been since the code was first generated.
> It's a horrible duplication of program logic and maintenance work.

If you need to change something about a generator's output,
you do it (always!) by changing the generator's input, or by
changing the generator.  Then you *re*generate the code.
There should never *be* any "unique modifications" to the output
of a code generator.

> Of course code generation is perfectly fine when the output is not
> intended to be read and maintained by a human.

"Read" and "maintained" are two different issues.
Depending on the tool-chain, it may be necessary for people to
read the generated code while debugging.

More information about the Haskell-Cafe mailing list