“To innovate is a mistake ’cause there’s nothing new under the sun.”
Wit’s All Been Done Before, Relient K
I threw out a lot of code today. It felt good.
I recently started coding some new components for a new (to me) system. Part of the work required generating XML with well-defined XSDs. I started with the available DOM framework which, unfortunately, did not support XSDs, only DTDs. So I had cobbled together something of my own to try to drive the XML generation from it. It just didn’t feel right.
Shortly afterward, I taught myself how to use the system’s very flexible and dynamic export mapping framework. It was built primarily for fixed record formats, not XML, but could be coaxed into XML structures. For example, the mapping mechanism supported hierarchies (tree structures) and higher-level unmapped tags, which were perfect for XML envelopes and the like. So, with a bit of recursive code and metadata, I got exactly the XML I needed with a wee bit of code. And I tossed aside a lot of really klunky code I no longer needed.
And so it goes with programming: read twice, write once. It often takes longer to first learn the lay of the land before blazing your own trail, and it may appear less productive. But significantly less code to do the same task is always a good thing.