Active vs. Passive Application Generation
Of course, nothing in programming is really right or wrong. Passive application generation is where you go through a wizard or run a script which generates code once to give you a starting point. You then modify that code by hand to make it do exactly what you want. The difference with active generation is that while you may be able to extend the code using some tricks, the code can be regenerated at any time, so as your requirements change (and they will change), you can continue to regenerate your repetitive code rather than having to maintain it by hand.
For example, imagine using a passive generator to create your DAO’s (I use this example because it is one of the first types of generation most OO programmers attempt). You run a generator to create a Data Access Object for each of your 70 business entities (hey, it’s a big project with products, users, categories, attributes, orders, order items and a bunch of other industry specific entities). You then add some custom code to each one to handle special cases (maybe you want a getBySKU() for your ProductDAO and so on).
Six months layer the customer comes back to you and asks for you to add rollback capabilities to the system. One of the pieces of this is that you need to either turn your updates into inserts (adding a new version of an object and setting it as the live version) and/or you need some kind of data table or file that you write every record to before updating or deleting it. If you had used an active generator, you’d just change your single DAO template, rerun the generator and you’d be done before lunch.
With a passive generator you’re still going to have to rewrite the code for one sample object, but then you’re going to have to manually update every single DAO for every single object, cutting and pasting the generic code and then manually replacing all of the parameters for every insert, update and delete. If you’re lucky you might be able to use search and replace but often the patterns are too complex and you’re stuck doing boring, error prone repetitive coding all night because it is a rush job.
Active generation is to passive generation what object oriented programming is to procedural programming. An approach that requires a little more thought up front to create a system that will be an order of magnitude easier to maintain down the line.


There are no comments for this entry.
[Add Comment]