I've been working on a little project the past 24 hours. Once again, I am impressed with the power of Ruby.
The project is a re-make of a utility I attempted at UPS. It's a macro expander, one that's tuned for XML.
Most macro expanders (at least the ones that I know) will expand a macro into text. But I want something a little different, one that expands macros into XML. ("But you can expand into XML! Just define the right expansion results!" I hear people cry. Yes, I can. But I need something more. Read on.)
I want to start with something like this:
.sheet name=budget
.row
.col
.value value=Jan
.col
.value value=100
.row
.col
.value value=Feb
.col
.value value=120
and end with something like this:
Notice the closing tags? I want the macro expander to provide them. I don't want a pair of macros (one for the open tag and a second for the closing tag). I want one macro that generates both tags.
I want the tags inserted at the proper place. That means that the expander must remember which macros it has expanded, and also have a sense of precedence. (I don't need the closing tag until another
I've built a small utility to perform this task. Using Ruby, it was easy to do. (My code is about 100 lines.) It reads a file of tag definitions (the definitions include the opening tag, the closing tag, and precedence) and then processes the macro script. It's not complete, but the basic logic works. I want to add variable substitution and some error handling.
What impresses me is the speed at which I can create a usable program.I've spent about three hours with Ruby. In C#, this would have taken me about seven hours. (That's an estimate. If I get a Windows machine working, and Visual Studio, I can re-write the program in C# and measure that effort. My guess is that I will spend more time re-writing the program in C# than I took writing it in Ruby.)
WhatI do not understand is the reason for the performance gain. I am faster in Ruby than in other languages. (How much faster depends on the other language.) Even when I solve the problem and get a good algorithm, I spend more time in the second implementation. (And I keep the second implementation simple -- no added features!)
So this is what I call the "Ruby puzzle": Why am I faster at development in Ruby? (Especially when I barely know the language?)
No comments:
Post a Comment