Thursday, February 12, 2009

Using templates to improve your database code

If you're like me, when it's time to do some coding the first thing you do is look for some code to copy. It's pretty sensible - why reinvent the wheel when there's something out there that may already do what you need?

But instead of just copying whatever code that may already exist that seems to suits your needs, extend the concept of copying code, and make a set of templates. For instance, you could have a set of stored procedure templates for the following purposes:

- Loading data feeds, say from an external vendor
- Pushing out data feeds
- Processing exception records
- Loading data warehouse fact tables
- Reporting
- Validating before inserting data

These are oriented to data warehouse needs, but of course you could create a similar set of stored procedure templates for an OLTP database. When you find yourself needing a new type of functionality, you would create a new template.

What are the benefits to creating templates like this, and making sure people use them? Well, for one, you're leveraging the capabilities of the most experienced developers to help out the less experienced ones. The more experienced developers would set up the templates, using the standards that have been set for error trapping, logging processes, etc. Then the more junior developers could write up the code for a particular need, using the template, knowing that they're following the correct coding standards (or at least, making a good start at it).

Some other benefits are that your code becomes more readable and maintainable when stored procedures follow templates. And, of course, coding becomes much faster if you have a trusted set of templates that you can start out with.

No comments:

Post a Comment