My XML Rant
I’ve mentioned that I am working on a code generator. Its quite a bit of fun. And I am purposefully going an “old-school” route by using System.CodeDom.Compiler.IndentedTextWriter to produce text. Yes I know this is NOT the most sexy way of doing things. If I were to follow the advice of people who have blazed this trail before me - like Scott Hanselman or Kathleen Dollard, I would certainly try to use XML and perhaps some XSLT to embody the definition of how my business object will look.
In essence both bloggers / authors have described their way of approaching the idea of code generation. Each uses his or her own logic to describe the needs for it. Scott talks about something along the lines of a “language factory” for example. And while I am guessing that both Scott and Kathleen have had success with their approaches I have personally found that moving logic out of my class code and into angle brackets just confuses the hell out of me.
Somewhere there is an argument to be made that xml models of the code that the generator produces is easier to maintain and change than having the same functionality embedded in code. Hogwash. (Again my personal opinion). I carefully design the output of the generator to match my needs. If those needs change, then it is certainly an unusual circumstance. Meaning that my entire framework of dealing with business objects has changed. Thats a biggie. And if that is the case, I would certainly take the time to change my generator code.
Call me an old fuddy-duddy but I like XML as a data transportation mechanism just fine. Even if I need to model XML documents into some sort of class structures, I can deal with that as well. XSD does a pretty good job there. But thats about where my love for XML ends. My buddy Dan has pulled his hair out so many times when trying to work with Hibernate in a similar setting, its not even funny. When something breaks in Hibernate you are left digging through mountains of angle brackets whilst trying to make sense of it. No fun. So there you have my justification for avoiding the fashionable approach to code gen. Hopefully by using a plain old text approach I will retain my hair whilst having an admittely less sexy piece of code.
Write a comment