Chapter 57. Generation Gap

Separate generated code from non-generated code by inheritance.

image

One of the difficulties of code generation is that generated code and handwritten code need to be treated differently. Generated code should never be edited by hand, otherwise you can’t safely regenerate it.

Generation Gap is about keeping the generated and handwritten parts separate by putting them in different classes linked by inheritance.

This pattern was first described by the late John Vlissides. In his formulation, the handwritten class was a subclass of the generated class. My description is a little different, based on the use I’ve seen; I really ...

Get Domain Specific Languages now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.