Google
 
Web asimjalis.blogspot.com

Thursday, June 24, 2004

Getting Rid of Programming Complexity

by Asim Jalis

Here is one way of getting rid of messy complexity in programming. This occurred to me today for a specific problem that I have been working on for some time. I am writing a program that automatically generates documentation in the Word XML format. Now the Word XML format is unpleasant. It's all XML, and human readable, so it is can be generated from a program as text. Still, the format is complex. So this is a difficult task and adds significantly to the complexity of the program. Here's the grain of an idea on how to get around this complexity: Instead of generating the XML in the program, create a template file and copy the XML from the template file to the generated file. The template file can be generated using Word, so creating it is not hard. While it's hard to write a program that generates complex XML, it is relatively easy to write a program that transforms existing XML and then inserts it in the right place. The general pattern here is: replace generation with transformation. This is related to the general idea of leverage. Instead of building something from scratch, find a way to make it from something you already have. The simplified version of the program leverages the template file instead of working hard to do the creation from scratch.