[Haskell-cafe] Code that writes code

Andrew Coppin andrewcoppin at btinternet.com
Sun Aug 22 05:33:30 EDT 2010

Jesse Schalken wrote:
>  I would also like to strongly discourage code generators.
> Any code that has to be "generated" can and should have its common
> characteristics separated out with only unique characterstic remaining
> typically with an interface (i.e. type class) or polymorphic type
> dividing the two, creating a separation of concerns (this is really just
> abstraction).

All the facilities of my family of types is accessed through type 
classes already.

> 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.

Uh... why edit the generated code? Why not just modify the generator and 
rerun it? That's kind of the entire *point* of using a code generator 
rather than writing it all by hand...

> Anyway, from my experience if you're generating code intended to be
> maintained by a human, you're doing it wrong. Though I am very
> interested to hear counter examples.

Yeah, I do get the feeling that if your code is repetative enough to 
require automation, you're probably doing it wrong...

More information about the Haskell-Cafe mailing list