Code Generation

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
VirtuosiMedia
Forum Contributor
Posts: 133
Joined: Thu Jun 12, 2008 6:16 pm

Code Generation

Post 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?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Code Generation

Post 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.
User avatar
inghamn
Forum Contributor
Posts: 174
Joined: Mon Apr 16, 2007 10:33 am
Location: Bloomington, IN, USA

Re: Code Generation

Post 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.
crazycoders
Forum Contributor
Posts: 260
Joined: Tue Oct 28, 2008 7:48 am
Location: Montreal, Qc, Canada

Re: Code Generation

Post 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.
User avatar
VirtuosiMedia
Forum Contributor
Posts: 133
Joined: Thu Jun 12, 2008 6:16 pm

Re: Code Generation

Post 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.
webaddict
Forum Commoner
Posts: 60
Joined: Wed Mar 14, 2007 6:55 am
Location: The Netherlands

Re: Code Generation

Post 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.
Post Reply