Keep Working, Worker Bee!


Ruby on Rails, macros, and code generation

Now that the quarter is over and my paper is submitted, I've had a little bit more breathing room and one of the things I've been doing is looking into Ruby on Rails. I can hardly say I'm a Rails expert after the few hours I've spent tinkering with it, but one thing about it really struck me: Rails does an awful lot of code generating for you. One of the first things they tell you to do in the beginners' tutorial is to run a battery of scripts that generate several ruby files in several different directories, all of which are generated pretty much systematically but have some minor variation based on the particulars of your application.

Of course my immediate Schemey reaction was to think that they had yet again confirmed that those without macro systems are doomed to reinvent them (probably poorly). But delving into it a little more, I'm not so sure I was right about that. I more-or-less randomly came across a blog post by David Hansson about why he thinks Rails deserves to be held in higher esteem than your average code-generation wizards. His basic argument is: Rails code generators are just creating stubs, not any real code; but they're creating the right stubs. New subclasses derive from the right base classes, even though they don't have methods. They're put in the right directories, and give you a good factoring from the beginning. He doesn't view it as a panacea, but he does think it's useful.

In essence, if I understand the argument correctly the RoR scripts aren't there to take away the drudgery of writing repetitive code so much as to be executable documentation on proper Rails use. That sounds like a much more intriguing idea to me.


  • Isn't having good documentation, especially executable documentation, just another drudgery of writing code that a code generation or macro system can help you with?

    Seems like a specific case of another advantage of meta-programming.

    By Blogger Jordan Henderson, at 18:56  

Post a Comment

<< Home