Google
 

Tuesday, August 28, 2007

Review: CodeSmith Professional

Code Generation

The concept of code generation has always fascinated me. When I first picked up a programming book, the thought of writing an application that could re-write and improve itself danced through my head. Later on though, that fantasy subsided, and the thought of an application that could do my work for me set in. While I still have not found my “Holy Grail”, CodeSmith, from http://www.CodeSmithTools.com comes close.

Data Layers

The projects I typically work on are generally based around the design of a database. Once the data structure is defined, there are really only two directions you can go. You can directly access the data using in-line SQL statements in your code, or you can create a data layer to simplify access to the data. In most cases, having a data layer is the best way to go because not only does it separate the functionality into more easily debuggable pieces, but also, once the data layer is complete, you can focus on the real functionality of your application. Before I discovered CodeSmith, I would spend nearly a third of my development time building the data layer. Using CodeSmith and the Nettiers Templates, it takes only a few minutes.

Once I've generated the data layer, I can immediately focus on the true functionality of my application. If during development of the functionality I discover that there was a flaw in the data model, its perfectly fine. I can go back and make the necessary changes to the database, and regenerate the data layer. The Nettiers templates allow you to utilize inheritance or partial classes to separate any modifications you make to the files it generates. When you regenerate the data layer, it leaves the files you customize intact so that you don't loose your changes. You may need to go through and update some of your existing code depending on the changes you have made, but because of the simple interfaces Nettiers provides, this process is generally fairly quick.

Repetitive Code

Data layers are not the only thing that CodeSmith is good for. CodeSmith provides a number of templates for different tasks out of the box, but its real power lies in the templates you can create yourself. When I am working on larger projects I generally find that a great deal of code is somewhat repetitive in design. By this I mean that I might have 20 different classes that implement a specific interface and need to provide similar implementations for the required methods. CodeSmith allows me to create templates that will generate the classes for me. This is especially useful when the classes can be generated data within the database or a list.

Up to this point, I've stressed mainly the positive qualities of CodeSmith. As with all tools, CodeSmith is not perfect. First of all, many of the templates packaged with it are poorly documented. Nettiers, which appears to be the main template they promote, seems to be the best designed, but has a few problems of its own. The template editor feels awkward, and I don't feel as productive with it as I am with Visual Studio. To compensate for this I often write the first class in Visual Studio, and then create the template from that.

Summary

I feel that CodeSmith is a great product that could use some improvement. The time I have saved using it has greatly overshadowed the frustration or dealing with its minor flaws. While I hope it is improved upon in the future, I will happily continue to use it as it is.

PROS

  • Nettiers provides a powerful data layer
  • Speeds development
  • Allows developers to focus on functionality

CONS

  • Weak integration with Visual Studio
  • Template editor is awkward

No comments: