Our application was just deployed in production on top of Whidbey Beta2!!! In addition to being a Whidbey success story, our application is a showcase for code generation techniques (and the great CodeSmith 2.6). In our DataAccess layer (about 4000 lines of code), a total of 10 lines were written by hand and that too to retrieve DB connection strings from configuration files. If we had been building on top of 1.1, we would have even bigger numbers for autogenerated lines of code) -- Whidbey generics eliminate the need to write code to create specialized collections of objects.
In addition, we used xsd schemas to generate partial classes that were later extended using hand written code. If you ask me, creating a XSD file is much easier than defining a class and defining a whole bunch of get / set props (well, arguably the Whidbey IDE makes it trivial, but you get the point).
The XSDs were processed using xsd.exe and XsdObjectGen (from MS). Both of these tools generate code from XSD definitions, but they work slightly differently. In addition, we used a couple of small homegrown tools to slightly tweak the output using regex (to change the generated class to "partial" for instance).
Also, it's pretty worthwhile to have a tool that generates code intelligently based on some of timestamp mechanism so that build doesn't take a long time.
Being a fan of the declarative programming, I have always been fascinated by the idea of AOP (Aspect Oriented Programming), but from the (failed) promise of COM+ interceptors (remember PDC 1999?) to the now deprecated CBOs (Context Bound Objects), it somehow hasn't fulfilled it's promise. For the uninitiated, the idea is it should be possible to provide certain functionality say for logging or tracing, just by means of an declarative attribute.
For example, instead of writing a typical call to a log or trace function like:
MyMethod()
{
Trace(“I am in MyMethod();“);
//Rest of method...
}
we could use something like:
[Trace]
MyMethod()
{
//Rest of method...
}
Granted, it's a trivial example, but aspects can be used to provide more interesting behaviours like Transactions, Post Conditions and Preconditions as well (a la Design by Contract). Indeed, EnterpriseServices used the AutoComplete attribute to automagically provide a transaction context and automatic completion and rollback.
So, if this is such a promising technology, where's the fly in ointment? For one thing, behaviour that's added at runtime can result in a severe performance penalty. Also, there may be “quirks” that may result from the interaction of such runtime behaviours (which may not be compatible w/ each other). In other words, if your software didn't behave as expected, would you blame your code or the “aspects”? And how would one go about debugging it?
If only there were a way to not incur the performance hit and also make it easy to debug the code so that you could actually see what was going on.
I think that's where static or compile time AOP comes into the picture. Watch this space for details...
With all the excellent code generation tools out there, it's really amazing that people still spend a whole bunch of time writing boiler plate code. What am I talking about here?
Let's take a look at a typical three tier web application:
- Web UI Layer
- BizFacade Layer
- Biz Layer
- DB Access Layer
- SP
In addition, since some people prefer dealing with objects rather DataSets, there's a Relational -> Object mapping layer that needs to be built. Naturally, where there are objects, there are collections and now we end up writing strong typed (of course) collections for each of those objects.
So, to retrieve and display some data, we had to go through the process of writing the SPs, coding the DB access layer to call the SPs, writing the objects, writing the collections, writing the code that mapped DataSets -> Objects....whew!!!
Is there something wrong with the picture here? Of course there is -- most or all of the things referenced the the above paragraph simply weren't meant to be written by hand. Or, if they were before, now is the time to STOP!!!
Stop making excuses for letting brain dead code hold you hostage and download the excellent (and free!!!) CodeSmith NOW!!!