Dynamic Programming vs. Application Generation
I’ve been having a bunch of fun over the last six months rewriting a CF5 application generator to take full advantage of Object Oriented design patterns and best practices. One of the things I am now playing with is how best to balance application generation with dynamic programming.
What’s the Difference?
The main difference between dynamic programming and application generation is how your metadata is used to affect your program execution (not when as some people think). Typically with application generation, metadata is combined with a template (string concatenation can also be used) to generate a script, which is then saved to the server hard drive ready for execution. This might happen in advance as some kind of generation or publishing step or it could happen as part of program execution (think: Reator). The key is that the program just generates a file to be executed that could theoretically have been coded by hand. With dynamic programming, the metadata is consumed and directs the program flow at runtime and no additional scripts or files are generated at all.
All other things being equal, application generation delivers better performing and simpler applications (because the complexity of the variability is abstracted out of the actual program into the generator), but dynamic programming can be more readable for developers without an application generation background and it is sometimes easier to prototype a dynamic application than to create all of the infrastructure required to implement a sophisticated application generator with a reusable metabase. Application generation solutions can also be more complex if you factor in the complexity of the generator and it’s associated infrastructure.
An Approach
I am finding that while my metadata schemas and domain specific languages are still quite fluid (I still have to keep refining the properties I use to describe things quite often), I am using dynamic programming wherever possible as it is much quicker to change a couple of parameters in an object and perhaps the interface to a method than to have to change the structure of the metabase and the associated code for retrieving that as well as the template for putting that into, so for now my approach will be to make pretty much everything use dynamic techniques and then to refactor to generation when appropriate.
The only exceptions will be for publishers or generators that are actually easier to implement using a "publish and include" pattern to solve a specific language limitation.


Cool - we should probably trade notes! What kind of apps do you generate?
Best Wishes,
Peter