The Ruby programming language is popping up everywhere this week. This is yet another in a series of indicators that something’s brewing in the programming language space.
First, on Monday, Mike Loukides blogged about almost trying to learn Ruby. It’s fun to see that he’s at least planning to learn Ruby. At JavaOne a couple of years ago, Mike told me that O’Reilly really wasn’t seeing much interest in Ruby. I replied that Ruby was still at the stage where the “thought leaders” were discovering it. By Tim O’Reilly’s own heuristic, where the alpha geeks are going, others soon follow, and I predicted that Ruby would soon become more popular. I know that O’Reilly’s seeing at least one indicator of increased Ruby interest, and maybe that’s one reason Mike’s planning to learn Ruby. This time, though, he decided he could get things done much faster using the tried-and-true Java way, and left his copy of PickAxe on the shelf.
Even though he decided not to actually try Ruby, he’s questioning whether it’s really useful. That’s not an auspicious start for Ruby this week, I guess. But back to Mike later.
Today, there are a couple of other things. (And if you average Monday and Wednesday, you get Tuesday, see?) First, Howard Lewis Ship (author of the best Java web framework) showed up on ruby-talk and also posted a very favorable blog about his first Ruby program. I was elated to see this. Howard’s expressed skepticism about dynamic languages to me at an NFJS conference, and was obliquely dismissive of Ruby in an earlier blog. But he’s tried it, and was really impressed. I like the way he describes his first Ruby program: “My trembling first journey into Ruby is […] sloppy, doesn’t report errors well, and took me too long to write (almost as long as it would have in Java!)” His first program in a new language, and his criterion for “took too long to write” is that it took nearly as long as it would’ve taken in Java. Sounds like Howard caught a glimpse of how productive Ruby can be once you know it well.
And I have to say that Howard’s first program is very nice! There are some things in it that an experienced Ruby developer would do differently, but it’s definitely not “a Java program written in Ruby.” Clearly Howard tried to learn not just the syntactic details of Ruby, but “the Ruby way.” That’s how we should all approach learning a new language.
So back to Mike Loukides. Maybe Ruby just isn’t right for Mike. I’m on record saying that, in the debate between static and dynamic typing, perhaps there’s not “one true way.” But I’m convinced that for most tasks, dynamic languages are the way to go. (And I was a Java bigot for quite a while!) It’s instructive to draw some lessons from the contrast between Mike’s and Howard’s experiences (and I’ll throw in a few general thoughts, too):
- Anytime you have learned one programming language really well, you’ve reached a kind of “local maximum.” To learn something different, even if it’s ultimately more powerful, means stepping down from your current peak of familiarity and expertise and flailing around like a newbie on ice skates for a while. You won’t see the benefits instantly. Howard describes his “trembling first journey,” and that’s how we can expect to feel the first time we try to write in a new programming language.
- Until your project is big enough that the gains start to outweigh the cost of the learning curve, the new language is bound to seem like a net loss. Howard’s 292-line Ruby program is about the smallest project where you could expect the effort to pay off. (After all, it took almost as long as writing it in Java! :-) Mike’s 25-line Java program is definitely too small.
- There are tradeoffs in languages, and Mike’s right: not declaring your variables means that you don’t have quite as much help debugging misspelled variable names. But the payoff comes in other ways, and not all of them have to do with writing the production code. Ruby_does_ make writing the code easier, I think – but it also makes it easier to write tests, and the code is easier to change.
- Not all “scripting languages” are alike. Mike implicitly criticizes the terseness of Perl (and also the “cryptic esthetic” of Perl culture, I suspect) when he lauds Java’s readability. But Perl is different from Java in many ways, and Ruby only shares some of those characteristics with Perl. The Ruby language and the Ruby community place a big emphasis on readable code.
My intent isn’t to bash Mike Loukides; he’s a great guy, and he definitely has a point: the overriding criterion is getting the job done, and for his recent purposes learning a whole new language was probably overkill. (And besides, it would be the height of foolishness to bite one of the hands that invited me to Foo Camp.) But I do hope he’ll make time to give Ruby a try, and give it a chance to prove itself on something reasonably sizable.
(Oh, and the other thing about Ruby that happened today? I noticed that, on the very cool website 43 Things, “Learn Ruby” is number four on the list of most popular things people would like to do. I wouldn’t read too much into that; I learned about 43 Things through the Ruby community, and I suspect that high placement is an artifact of the way word of the site has spread. But it was still a pleasure to see.)