Under the hood and working with .Net, TDD, Software Design, and Agile Stuff
I relearned a couple of lessons today about working with database intensive applications. Fortunately, I was merely writing test automation code and I caught my problems fairly quickly, but...
- You should get the System DateTime.Now in a consistent manner. It's either assigned by the database clock or the application server clock (assuming a cluster is synchronized somehow), but never both. I got burned for a little while today because my system clock is apparently a few moments behind the database clock.
- Don't play with strange databases. If you're using a legacy database schema for the first time, assume nothing. Treat them like a poisonous snake that needs to be handled with care. Every legacy database seems to be littered with idiosynchracies just waiting to jump out at you. That innocuous lookup table may be vital, referential integrity might be lacking, and there could be triggers lurking under the water waiting to take a bite out of developers swimming nearby. I swear, and I know somebody is going to argue with me here, that the fastest way to make your code completely unmaintainable is putting business logic in triggers. As much as I detest business logic in sproc's, at least you can generally see the flow of the code.
- Integrating through the database is not a good idea. I've seen a handful of systems that integrate by having the downstream application determine it's workflow by scraping through the audit trail tables of the upstream application. Everytime, the result is tears and brittle systems. As an example, I'm thinking of designs where you might poll a table and look for any changes since the last time the polling job executed.
- While convenient, using database tables to store application metadata can potentially cause you a great deal of friction in setting up the application for testing, especially when you're using a lot of surrogate keys (autonumber or sequence) for the metadata. A single xml file is easier, and lends itself more readily to being versioned in source control than the corresponding storage in a dozen database tables. At a bare minimum, have a way to suck in the database configuration from a single file. If the application is hard to set up, test and build automation becomes very difficult and your velocity will suffer.

About Jeremy D. Miller
Jeremy began his IT career writing "Shadow IT" applications to automate his engineering documentation, then wandered into software development because it looked like more fun. Jeremy previously worked as a systems architect building mission critical supply chain software for a Fortune 100 company and learned agile development practices as a .Net consultant at ThoughtWorks, one of the pioneers of agile development. Jeremy is the author of the open source StructureMap (http://structuremap.sourceforge.net) tool for Dependency Injection with .Net and the forthcoming StoryTeller (http://storyteller.tigris.org) tool for supercharged FIT testing in .Net. Jeremy's thoughts on just about everything software related can be found on his weblog "The Shade Tree Developer" at http://codebetter.com/blogs/jeremy.miller, part of the popular CodeBetter site. Jeremy is a Microsoft MVP for C#.