I’ve always been a big fan of making the computer do the arduous part of the work so I can concentrate on the more interesting parts. When writing software, that’s generally meant relying on terse or sophisticated languages like Perl and Matlab. I’m currently taking it to the next level, though, by using code-generation tool and frameworks to generate complete code layers with full unit tests.
The problem is a common one: a legacy web application and database without much proper architecture or separation. The whole thing should really be thrown out; using agile methods we could probably rewrite the pieces that are still relevant much faster than refactoring the entire thing. However, the business has dictated that the a new architecture and interface be built on the existing database.
The new architecture uses NHibernate’s object relational mapping to persist business objects to and from database storage and Castle Windsor’s inversion of control implementation to separate data access from business logic and services. And since I’m now a devotee of test-driven development, it’s all covered by NUnit tests.
The whole thing is generated by a set of custom CodeSmith templates, which handle a number of quirky legacy design decisions. At 150 tables and 7 files each, it yields 1050 files containing 450 unit tests which take about 6 hours to run
It’s probably six months worth of work, and I was able to do finish it single-handedly in a week with just a basic template as a start.
As one architect I interviewed with last year put it, software development is finally moving away from repetitive handcrafting to more industrialized production where people will do more concept work and less coding. For instance, this video shows .netTiers producing a whole web applications from just the database design.


