Code Generation

This is a list of some advantages to code generation over fully dynamic programming. It might be useful if you ever need to justify spending time writing code generation tools. After working on a fairly elaborate code generator that created simple SQL table editors for MySQL, I've learned a few things.

So why use a generator? Because it unrolls a loop or two, in the right places, leading to faster, less confusing code that, partially, self-documents. Generated code tends to expose the structure of the application, as code. Each chunk of code is specialized, and not responsible for large areas of the application.

Dynamic code tends to be harder to understand, because the behavior of the software can be assessed only at runtime. In a system like PHP, where scripts start up, execute, and exit in a fraction of a second, it's hard to debug dynamic software.