Code Generation Is Smell

Well, it's not really a smell in itself. After all, code generation is what compilers do. The smell comes from having to maintain the output of the code generation, instead of being able to maintain the input. That's why you should never edit the output of BISON or FLEX, but only their input files. Indeed, their output contains a strongly worded warning against modifying the generated code.

One of the lessons inherent in these tools is the ability to include absolutely arbitrary code in the target language as part of the input file.

For a moment, see TargetLanguage (TL) and DomainSpecificLanguage (DSL).

We generally want the computer to generate TL for us. By using HighLevelLanguage and a compiler, that's exactly what happens. However, for a long time after the adoption of the first few compilers, it was still common for people to take the output and start hacking on the assembler code. This lead to all manner of problems in every realm from the political to the psychological, and even to programmers who quit in frustration because the perceived quality of the code from the compilers of the day was less than hand-rolled assembler code.

These days, we've got all these GUI tools and code generators and so forth that turn DSL into TL, but then people go and hack the TL afterwards. Do people not learn? If you need to be able to edit the TL, then it needs to be part of the input to the DSL, just as modern CeeLanguage compilers allow the inclusion of embedded assembler codes.
EditHint: Merge with CodeGenerationIsaDesignSmell

EditText of this page (last edited April 25, 2006) or FindPage with title or text search