|
||||||||||||
hy do people use computers? We use computers because they make us more productive. Using a word processor is more efficient than writing a manuscript in pencil. An electronic spreadsheet is more efficient, accurate, and valuable than its paper counterpart. As engineers we build time-saving applications for others but never think to apply the power of computers to our own problems.
Code generation is a time-saving technique that helps engineers do better, more creative, and useful work by reducing redundant hand-coding. In this world of increasingly code-intensive frameworks, the value of replacing laborious hand-coding with code generation is acute and, thus, its popularity is increasing. EJB is an excellent example of a complex and code-intensive framework. Supporting a single database table in an EJB framework requires building up to seven different classes and interfaces. And of course, even a simple database application today has 20 or more tables. The coding work adds up fast. EJB's infrastructure code is laborious scaffolding-style code where the best you can hope for is to not screw it up. It's repetitive and therefore difficult to maintain. It's not code where you can excel or that requires any creativity to write. For these reasons alone EJB code should always be built using an active generator.
Dealing with Skepticism
Code generation is copy-and-paste coding.
Generating all of the code now means I won't have a job tomorrow. Code generators follow the 80/20 rule. They solve most of the problems, but not all of the problems. There are always features and edge cases that will need hand-coding. Even if code generation could build 100 percent of the application, there will still be an endless supply of boring meetings about feature design.
Generating code is a design smell. The choice of platform is often not up to the engineer on the front lines. If EJB is the chosen platform, and it often is, then you need EJB code to complete the project. What is your choice is how you build the code. You can write the code by hand or generate it. Particularly on EJB projects, generation will get you complete code quickly.
Nobody will understand the generator but me. If there are several teams you may want to hold a different brown bag to show the architecture of the generator and also to brainstorm other uses of the generators. For example, you may come up with great ideas on how to use multiple generators together, how to generate build processes, or how to generate documentation. Documentation of the generators itself is critical to widespread acceptance. You need introductory documentation for new engineers and in-depth documentation for those maintaining the generator. Even if you use an off-the-shelf generator such as XDoclet or UML2EJB you still have to write up documentation for how the generator is configured for your environment.
Engineers will start disregarding the 'do not edit' comments and eventually the generator will fall out of use. You can mitigate the problem in two ways. The first is accurate and well-maintained documentation that focuses on what the generator does and how it is used. The other is the usability of the generator itself. Generators need to have reasonably friendly command-line interfaces that report intelligent errors and positively report success. If possible, the generator should be integrated into the IDE or the automated build process when appropriate. It comes down to a team dynamic. If you have a team that is supportive of the generator and maintains it properly, you wont have issues. If the generator is maintained by one guy that nobody talks to because he sits in a corner, you'll have problems.
My schema is too complex; a generator will never be able to handle all of the edge cases. I recommend building a few EJBs to represent the various types of tables and relationships in your schema. This will give you a feel for what you would like to see as output from a generator. Then use a couple of different generators to see which one works for your project and will produce code that matches your design and coding standards.
The generator will limit our creativity.
I'll push a button and something will make lots of code that I don't understand.
My project isn't ready for a generator.
|
||||||||||||
|
|
||||||||||||
|