I’ve long been an advocate of using code templates/generation to expedite an otherwise tedious and lengthy development process for what usually is boilerplate code. That being said, one of the obvious downsides is that a small error inside a code template is magnified tens, hundreds or thousands of times. Today I found an error in a CodeSmith template that has had widespread implications on an entire application that I’m currently working on. The fix for this problem is simply inserting 1 statement into an if clause, yet the net effect of not having it there was that many portions of a large application didn’t function correctly. This particular error is isolated to the application I’m working on – and luckily was caught during the QA process, but imagine that we have dozens or hundreds of applications in production and then later find such a defect. What then?
Because I know I’m not alone in using CodeSmith to generate code, I’d like to encourage us all to learn from my mistake and consider how, when and where you use templates and their overall impact on the applications you’re working on. Specifically, I’m interested in suggestions for ways to mitigate the risk associated with this activity. In my previous example, we’re actually generating unit tests with the code that gets generated, but in this case, the unit tests failed to detect the error that has caused so much heartache.
fdfcea38-bdaf-4147-a27d-5930abd6207c|0|.0
Development
code generation