A few thoughts on code generation...
Quote:
|
Originally Posted by The Pragmatic Programmer
1. Passive code generators are run once to produce a result. from that point forward the result becomes freestanding -- It is divorced from the code generator.
2. Active Code generators are used each time their results are required. The result is a throw-away -- It can always be reproduced by the code generator.
|
I have a definite preference for active code generators. These are things like compilers. They produce a result which you either use the result as a whole, or process further, but never edit by hand.
I dislike wizards, which are passive code generators that generate a bunch of code up front, which you then modify.
To me, this seems like automated copy-paste-modify coding.
The other thing is that wizards sometimes hide complexity which will come back to haunt you later. The Pragmatic Programmer covers this in a section called "Evil Wizards:"
Quote:
|
Originally Posted by The Pragmatic Programmer
Tip 50: Don't Use Wizard Code You Don't Understand.
|
As I said on the WACT mailing list:
I've always felt that the more wizards a programming environment had, the worse it was.
What these wizards do is try to cover up the fact that there are too many dependencies and complicated structures in the programming environment. Instead of removing the complexity, wizards just hide it, leaving it to burn you another day.
Think about hello world in Java versus Hello world in PHP. In Java, you almost have to have a wizard just to get to the hello world running. I've been programming for 20 years and I still have trouble running naked java applications with class path configurations & enforced directory structures, etc. A simple hello world is one of PHPs greatest strengths.
If your initial setup is so complicated as to need a wizard, the solution isn't to write a wizard, but to simplify the setup.
Anyway, I think that code generation is an appropriate tool for a DAO solution. As long as it does not require (or even allow) you to manually edit the generated product in any way. Think active, not passive.