Saturday, May 14, 2005

Code Generation Complete!

I am quickly becoming a ruby convert. In under 200 lines of code, I now have a code generator for my manager business classes and interfaces. This should save me countless hours of repetitive copy/pasting of code for these classes.

Using templates for both the interface and manager, I can configure the generator to build any number of classes and interfaces and all the variations like class name, request and response type, exception messages, and list types for the filters, are plugged into the template markers. The generator can build as many methods for the requests and responses that the manager needs to handle.

My next steps will be to generate the entity class interfaces from the xsd file, but before I can do that, I need to ramp up on XML in Ruby. Once I've done that, I might also reformat the config file to use XML instead of comma delimited to make it easier reading and less prone to error in the setup. Finally I may need to do some post-processing on the entity classes generated by XsdObjectGen to add some of our tweaks to the entities like having them conform to the interfaces.

Ultimately I owe the inspiration for all this to the Pragmatic Programmers and their excellent books and online articles. There's also a book, Code Generation In Action, with examples in Ruby, that might be reading for more on this as I know I'm just touching the surface of what is possible.

And kudos to the folks that created TextMate. I've been demoing the beta version for all my ruby coding, and I'm really diggin' it. It's a very snappy little app; the responsiveness is the first thing you notice. Then there's loads of very useful features like code-folding/unfolding, system escaping, projects, snippets, macros, and tons more I haven't explored yet. I just found the Bundles editor which allows to you customize macros, templates, and commands. It's extremely useful. You can assign anything in the bundle editor a keyboard shortcut, and control different aspects of its behavior. And I was very impressed by the responsiveness of their support team. I submitted a bug and heard back immediately.

Before I buy, I will give the latest BBEdit one last chance (I owe them that as a long-time user) and I'll give SubEthaEdit another once over. But TextMate is the current lead by several lengths.

So now I've used Ruby on Mac OS X to generate C# classes for the .NET Framework. And it was definitely more fun than coding in C# and VS.NET.

Maybe this is what Microsoft means when they talk about interoperability? ;-) If so, sign me up.


Post a Comment

Links to this post:

Create a Link

<< Home