Code Generation
Moderator: General Moderators
- VirtuosiMedia
- Forum Contributor
- Posts: 133
- Joined: Thu Jun 12, 2008 6:16 pm
Code Generation
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
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.
- inghamn
- Forum Contributor
- Posts: 174
- Joined: Mon Apr 16, 2007 10:33 am
- Location: Bloomington, IN, USA
Re: Code Generation
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.
-
crazycoders
- Forum Contributor
- Posts: 260
- Joined: Tue Oct 28, 2008 7:48 am
- Location: Montreal, Qc, Canada
Re: Code Generation
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.
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.
- VirtuosiMedia
- Forum Contributor
- Posts: 133
- Joined: Thu Jun 12, 2008 6:16 pm
Re: Code Generation
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
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:What are some of the tasks you've automated or generate code for?
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.VirtuosiMedia wrote:generating forms, complete with filtering, validation, and database interaction.
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.