Friday, May 20, 2005

Pragmatic Studio

The pragmatic programmers are coming to town in July for a two day seminar on source control (cvs and subversion), unit testing (jUnit and NUnit), and project automation (ant and NAnt). At $650, I think it's very reasonable. I've signed up. That gives me a couple of months to finish reading Dave's books (Unit Testing in C#, Programming Ruby, and the Pragmatic Programmer).

Rails model validation

The more I look at rails, the more impressed I become. I've done validation on various web platforms, and nothing is as straightforward and sensible as the way Rails handles it. I had liked ASP.NET's validator controls, but that was before I experienced the sweet simplicity of the Rails ActiveRecord validation methods. The problem with ASP.NET, and most other frameworks, is that you have to duplicate validation in the view (ui controls, javascript) and the model (business objects). With Rails, in the spirit of DRY, it is coded in the one place it should be, the model.

class Category < ActiveRecord::Base
validates_length_of :category,
:within => 1..20
validates_uniqueness_of :category,
:message => "already exists"
validates_format_of :category,
:with => /^[^<>]+$/,
:message => "no brackets!"
validates_format_of :category,
:with => /^[^(fudge|shucks|gosh darn)]+$/i,
:message => "no cursing!"

Thursday, May 19, 2005

Ta-da list sorting

Ta-da has one of the nicest list sorting interfaces that I've seen to date. And it works!

Sunday, May 15, 2005


originally uploaded by vcosby.
Lots of Ellie time today. We hung out together while Lindsay and Harper went to Henry's birthday party. She's such good company.

I just set up a Flikr account. I like the blog integration that allows me to post directly from Flikr.

Amazon Associate Links

While Amazon does make it easy to create links for associates to link to their product listings from your site, they include lots of inline css and attributes that you don't want if you are using your own imported styles. And the process is still time-consuming and repetitive.

So I coded an AmazonLinkBuilder class in Ruby that builds the link HTML for the books I'm reading and have read. Given a config file with the title, isbn, and (optionally) rating, the link builder determines if it's a Book or a RatedBook (one that I've read), and then builds the links appropriately.

I don't know of any way to update my blogger template outside blogger's UI, so I still have to do that piece manually. I guess I should submit it as a feature request if it's not possible.

my iPod is making me healthier

I had stopped running and I finally know why. Boredom. Now that I have an iPod Shuffle I can bring along my music and listen to podcasts or ‘books on disk’ while I’m running. Finally a gadget that is good for me!

But I think this is going a bit far, don’t you?

Saturday, May 14, 2005

43 Things... almost

Getting up there. Added a slew of goals today. I should add a goal to make more time to meet my goals...

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.

Friday, May 13, 2005

Code Generation

I've been thinking about building a code generator for some business objects I'm working on for a project. A lot of the stuff is repeating a pattern that occurs to me would lend itself well to code generation. I think I could build a template .cs file that could be parsed to build new classes with the stubs and basic code for all manager methods. For the interfaces, a generator could parse the xsd schema that I'm using to build the entity objects. I'm using XsdObjectGen for those already, but it doesn't include an option for interfaces. If this could speed up things even more, it might be worth spending a couple hours on it.

I've never done it in anything like this except in Perl, and my Perl is extremely rusty. I haven't had a chance to start reading Kathleen Dollard's code generation book, so I might use Ruby or Python instead of C#.

Sunday, May 08, 2005

Riding the rails with my ticket out of .NET hell

I took a job 4 years ago with the understanding I’d be working in Java, but then my team got re-orged into another group and I’ve been stuck doing C#, .NET, and COM interop ever since.

Ruby and RoR (Ruby on Rails) look like the perfect way for me to get back to my open source roots (Perl). I’d been picking up Python off and on, but since I’ve been looking at Ruby, I’m impressed. It’s as if Perl, Python, and Smalltalk had a menage a trois and had an offspring named Ruby.

I’m into chapter 5 of the pickaxe book and getting back some of the enthusiasm I felt when I first started programming. Time to get the joy back in this work, or ditch it and start a llama farm. Since I doubt I’ll be able to quit my day job just now, I need something that’s built for rapid development, and RoR is looking like it’s hit the sweet-spot.

I’ve got RoR, mod_ruby, and eruby installed on my powerbook, and I followed along with the blogging tutorial on the rails site. I plan to learn Ruby and RoR in parallel.

I’m hoping to attend OSCON in Portland this August, at least for some of the Ruby and RoR tutorials, though I hope to be far along by then, putting together my own site along with some ideas I have for live services.