Code Generation vs OO

Early and Adopter suggest that sometimes a good OO design can get the same results as code generators.

Any code generator needs some kind of abstraction as the input. It can be a database metadata, a domain specific language, etc.

ASP.NET is a code generator. It reads an .ASPX file and generates a .cs file. The ASP.NET team built a domain-specific language for defining web forms.

Of course you can write the same ASP.NET page in an OO way. Just read the .cs file that is generated and refactor it to make it look like code you could have written.

Then compare it with the ASPX code and see which one is easier to read and easier to maintain.

You also have ASP.NET controls, like <asp:CompareValidator></asp:CompareValidator> which are translated to method calls that _generate_ HTML code. Again, they built an abstraction that generates code.

So, if you thought you were not using a code-generation tool in your .NET project, think again ;)

 

No Comments