Page 1 of 1
Code Generation
Posted: Thu Mar 12, 2009 2:31 am
by VirtuosiMedia
I've recently written a few little scripts that generate code for me automatically. One generates usable classes for my database interaction layer and another creates a template module with folders and classes which I later fill in the details for. They both save me quite a bit of time in terms of setup, but I haven't gone crazy with it. I'm curious to see how much others use code generation. What are some of the tasks you've automated or generate code for?
Re: Code Generation
Posted: Thu Mar 12, 2009 3:49 am
by Weirdan
Currently where I work we use Propel to generate database access classes, and we will be using Zend_Tool (once it out of incubator) to generate controller skeletons. So, basically, same as you.
Re: Code Generation
Posted: Thu Mar 12, 2009 8:16 am
by inghamn
I have a base working application with users and roles that I start from. Then in the framework that I wrote, I generate scaffolded code for all the models, controllers, and views from looking at the database. The scaffolding is saved in a stubs directory, so I can copy in the files or changes that I want. It gives a good basic starting point that I can easily customize.
Re: Code Generation
Posted: Thu Mar 12, 2009 9:21 am
by crazycoders
I did create my own generator that creates a set of classes used for the same purpose, i didn't know anything about propel and don't know the differences, but it's a nice way of saving time.
Further more it enforces correct generation of your sql statements since it's all automated so you can't really do errors and your errors will be more at the logical level than at the development level.
Re: Code Generation
Posted: Thu Mar 12, 2009 8:04 pm
by VirtuosiMedia
As a followup, what kind of things do you think are likely candidates for code generation, even if you haven't done them yourself? I'm playing around with the idea of generating forms, complete with filtering, validation, and database interaction.
Re: Code Generation
Posted: Fri Mar 13, 2009 4:44 am
by webaddict
VirtuosiMedia wrote:What are some of the tasks you've automated or generate code for?
In terms of webapplications, I've automated the creation of forms, because I dislike writing them. Also, I've automated the creation of controllerfiles and the actual controllers, but that's nothing fancy: just some skeletons from which I can start writing.
VirtuosiMedia wrote:generating forms, complete with filtering, validation, and database interaction.
Generating forms in my case is simply generating the HTML and some PHP code for displaying errors and so on. Filtering and validation obviously have nothing to do with the HTML, and I tend to write that myself. Nevertheless, it's interesting to try and come up with a generator for filtering and validation.
The problem is that I'm using a Domain Model and I'm using it like it was meant to be used: to contain all logic of the application. You can't extract that from the database layout, but perhaps using a certain syntax to create the classes, including filtering and validation might make sense.