Ruby On Rails

It catches your attention when a respected member of the Java development community says Ruby On Rails may be a successor to Java. You've heard of Rails, of course. It's that hot Ruby-based MVC-patterned full-stack framework for developing web applications that babysit databases.


May 16, 2006
URL:http://www.drdobbs.com/architecture-and-design/ruby-on-rails/187203512

When a respected member of the Java development community says it may be time to look around for a successor to Java, it sort of catches your attention.

In Beyond Java, Bruce Tate describes the epiphany he reached when one of his clients dumped Java right in the middle of development of an application. Tate and his partner had decided, perhaps in one of those fits of whimsy that can hit you when you're busiest, to rewrite one component of the application in Rails. Just, you know, out of curiosity.

Tate says it shook him to his Java-loving core when the Rails rewrite took four nights of coding compared to four months for the Java build, then outperformed the Java version while weighing in at about a fifth the number of lines of code.

Remember that scene in My Cousin Vinny where sort-of lawyer Vinny Gambini (Joe Pesci) utterly destroys a witness and the formerly skeptical defendant jumps up, fires the stuttering public defender, points to Vinny, and declares, "I want him"? Apparently, Tate's client fired Java like a lawyer with a speech impediment.

The experience drove Tate to consider alternatives to Java. Of course, neither Tate nor anyone else expects Java to lose dominance soon. If you believe IBM, in a given day the world sees more COBOL transactions processed than web pages viewed. De gustibus non disputandum est, and languages don't die overnight. But Tate was forced to conclude that Rails just might have what it takes to supplant Java for certain purposes.

You've heard of Rails, of course. It's that hot Ruby-based Model-View-Controller-patterned full-stack framework for developing web applications that babysit databases.

Sorry; I should define my terms. Here's what I mean by "hot": At this year's Jolt Awards, Rails snagged the top prize for web development tools, while the top technical book pick was Agile Web Development with Rails. When the First International Rails Conference sold out in less than a week, the organizers added 150 seats—and sold all of those in 24 hours. In the past three months, Rails has been on the radar of publications ranging from BusinessWeek to Wired. Employers are starting to ask applicants for Ruby and Rails experience (so far, this only applies to applicants for programming jobs).

Rails 1.0 was released in December 2005, and there are a number of Rails-developed applications running on the Web right now—see the www.rubyonrails.org site or Wikipedia for lists. One such application, MeasureMap, was snapped up by Google.

Rails is clearly getting a lot of attention, but it's more than just the flavor of the month. For a growing number of web application developers, Rails seems to have hit some sort of sweet spot.

Ruby Features

What is it about Rails that makes it the right tool for developing database-babysitting web apps?

At the top of the list has to be productivity. That was the tipping factor for Bruce Tate's customer, and it's surely the killer requirement for a web development tool, just as performance is the killer requirement for PC game development. Exactly how Rails makes you more productive comes down to a number of decisions that together make up a programming style. One of those decisions is the principle of Convention over Configuration.

Take plurals, for example. Rails automatically and dynamically fleshes out your Model objects based on your database, and does so with a sophisticated understanding of English plurals: A "customers" table will result in a Customer model, and a table named "people" will give you a Person model. You can override these decisions, but bowing to Rails' conventions saves a lot of coding.

One-stop shopping. Rails is a fully integrated web application framework. All you have to add to it are a web server and database. And the Model, View, and Controller components of your app are intelligently integrated without effort on your part.

Polish. Although Rails is a free, open application, it emerged into the wild only after serious real-world testing. Its creator David Hansson (see "A Conversation with David Hansson") used Rails to develop three successful web applications for his company. It's been out of beta since December, which technically makes it more mature than nine out of ten Google apps, snark snark.

Then there's Ruby, a language that combines the uncompromising object orientation of Smalltalk with the immediacy of Perl, Python, or PHP. Yukihiro "Matz" Matsumoto wanted to create a language that made programmers happy. Ruby is one of the most approachable languages we've ever seen, and Rails honors Ruby by trying to extend that approachability to the level of metaprogramming.

Among the features of Ruby that Rails makes powerful use of are:

Right Time for Rails?

But maybe it all comes down to timing. "Ruby on Rails had the good fortune to get the timing right," Hansson says. "There's enough awareness and sympathy for the agile methodologies we're aligning our philosophy with. Enough cheap CPU cycles available to make performance a nonissue for most applications. Enough understanding of what can be generalized in web development. And finally, there's enough people sick and tired of their existing development environments to look beyond the corporate dictates and explore greener fields."

Of course, this is the developer of Rails building the buzz for his baby, but effective marketing is one of the things Rails has going for it. Rails expert Chad Fowler says, "Marketing really is an important part, not just of what's driving interest in Rails, but of the Rails culture. For years, the geek culture has been extremely suspicious of anything related to marketing. They're starting to see, through Rails and other successes, that if you really believe in a technology and you want to see others succeed while using it, you need to market it. If nobody knows about it, nobody's going to use it."

A good place to investigate the power and simplicity of Rails is in the way it interfaces with your database. Rails implements the Model component of your MVC application via the ActiveRecord class (see Martin Fowler's Patterns of Enterprise Application Architecture, Addison-Wesley 2002, for a discussion of ActiveRecord). ActiveRecord wraps database records, encapsulates database access, and adds logic pertinent to the data. When you build your first Rails app, it's really surprising to see how, through the magic of reflection and Convention over Configuration, Rails is able to free you of most of the effort of integrating your database into all phases of your application. This line of Ruby:


class Person < ActiveRecord::Base; end

"is all the code you need," Fowler explains, "to have a full functional Object-Relational Mapping to a database table called 'people.' It just works."

But wait, there's more.

This is merely an overview of the Ruby on Rails phenomenon. DDJ will be tracking Rails closely in the coming months because it may represent a historic tipping point in development environments. Here are some places to go to learn more about Rails:

Books and articles. Dave Thomas at the Pragmatic Bookshelf seems to have signed most of the Ruby and Rails authors, including Chad Fowler (Rails Recipes) and David Hansson (Agile Web Development with Rails). But O'Reilly & Associates has Bruce Tate working on Ruby on Rails: Up and Running, Apress will be coming out with Beginning Ruby on Rails, and there should be several other Rails books released in the coming months. There are a number of books out on Ruby, and Pragmatic's Programming Ruby is readable online (www.rubycentral.com/book). The official Rails web site (www.rubyonrails.org) has links to a number of useful how-to articles, such as "Using Rails for web dev on Mac OS X" at Apple's Developer Connection, the starting point for Mac-based Rails development.

Blogs, web sites, and lists. In addition to the links already mentioned, see www.loudthinking.com and www.chadfowler.com (Hansson and Fowler's blogs) for links to more Rails info. Digital Media Minute has the "Top 12 Ruby on Rails Tutorials" (www.digitalmediaminute.com/article/ 1816/top-ruby-on-rails-tutorials). The Rails Wiki (wiki.rubyonrails.com) has documentation, discussion, and advice on Rails-friendly web hosting. Two starting points for Ruby information are groups.google.com/group/comp.lang.ruby and www.ruby-lang.org.

A Conversation with David Heinemeier Hansson

DDJ: In Beyond Java, Bruce Tate argues that the Java platform is getting in the way of programmer productivity, compelling programmers to look for an alternative, perhaps Ruby and Ruby on Rails. What do you think of his assessment of the Java platform today?

DHH: Bruce is spot on. Java has had a great run for the last 10 years. There's plenty to be proud of over that stretch. And Java will be around for a very long time to come. But I don't believe there's room at the top of the hill anymore. Its patronizing roots and the complexities needed to cope with those have grown stale. A wonderful world of possibilities is opened when you replace "you can't" with "you shouldn't (unless)." One where use cases and practices can emerge and grow beyond the limited set of possible uses a supposedly omniscient language designer could predict back in the early '90s.

DDJ: What's to stop Ruby on Rails from evolving into what Java/J2EE has become?

DHH: Determination. Unlike commercial entities, we're not at the mercy of the next big deal. We're not looking to create a framework that's capable of solving the 5 percent hardest problems in the world. That's our sweet spot: catering to the mass of applications where a common set of conventions can be widely applicable. Where most people can need and desire the same thing for most of the work. So we're very conscious about the fact that Rails will never solve 100 percent of anyone's problems. If we can just get the 80 percent streamlined, you'll have more than enough time left over to make a truly great application by being unique in the last 20 percent.

DDJ: Is there a danger of people applying RoR to tasks for which it is not suited, and growing the platform in unhelpful, distracting directions?

DHH: You're free to take Ruby on Rails in whatever direction you please for your own project. It's open and free software. Just don't expect that we'll accept your contributions in the core automatically. We're turning down patches and ideas for the core of Rails all the time. So I don't fear this distraction too much. DDJ

Terms of Service | Privacy Statement | Copyright © 2024 UBM Tech, All rights reserved.