Issue No.02 - February (2006 vol.39)
Published by the IEEE Computer Society
DOI Bookmark: http://doi.ieeecomputersociety.org/10.1109/MC.2006.74
Proponents claim that Ruby on Rails offers a fast, productive programming approach that produces reliable, clean applications more quickly, using less code.
In software development, there has long been a gap between quick but not-so-clean programming approaches like PHP scripting and slow but clean and solid approaches such as Java.
Many programmers have wanted the best of both worlds: a fast, productive approach that produces reliable, clean applications more quickly, using less code. Enter Ruby on Rails.
The Rails application-development framework is based on Ruby, an open source, object-oriented scripting language similar to Perl and Smalltalk. Rails uses integrated programming packages and preset code, known as conventions, designed to be complete and ready to use immediately, without configuration.
This differs from many other programming environments, such as those based on Java, that require using several frameworks—which developers must configure because they don't natively work together—to get all desired capabilities.
Proponents say Rails is best suited to building infrastructures that pull information from a database to a Web application such as those used in e-commerce, online communities, and data retrieval.
Several projects have already used Rails, but the approach is still very new. "I would guess no more than 5 percent of programmers use [it] regularly," said Stephen Downes, senior researcher at the National Research Council of Canada's Institute for Information Technology. However, as the " Putting Ruby on Rails to Use" sidebar indicates, the approach is growing in popularity.
Nonetheless, Rails still faces challenges, such as developers' reluctance to use a relatively untested framework instead of more established approaches such as Sun Microsystems' Java and Microsoft's .NET.
About Ruby on rails
Rails, released publicly in 2004, is free and available under an MIT license ( www.opensource.org/licenses/mit-license.php).
David Heinemeier Hansson, a partner and programmer with the 37signals application-development firm, designed Rails by extracting various features from Basecamp, a Ruby-based project-management tool he worked on.
Rails turned the general-purpose programming language of Ruby into a specific solution for creating Web applications, giving it direction and thereby putting "Ruby on Rails," he explained.
Rails uses a model-view-controller approach to application development.
The framework provides the tools necessary to produce a Web-application model, which is the underlying program itself. The Active Record package, Rails' object-relational mapper, connects programming objects to database tables so that users can access information they want from a database.
Unlike most ORMs—programs that map objects to specific information fields in a relational database—Rails' ORM is based on convention over configuration, according to Heinemeier Hansson. This means developers don't have to spend time designing and configuring code that specifies how a table relates to a class of objects, as is the case with many other programming environments. Rails accomplishes this automatically via precoded conventions and templates.
Rails' Action View component generates views, which represent the visual appearance of an application's response to a request.
In application development, controllers connect the program with its interface and handle communication between them. The Action Controller performs controller development in Rails.
The Action Controller receives Web-based requests for information in a database, parses and decodes them to determine what the user wants, and then decides which piece of application code should handle the task, explained Curt Hibbs, a Boeing software developer and a Rails advocate.
Rails' Action View template renders the HTML response to the request, which it then sends back to the browser.
Action View templates work with Ruby and thereby simplify developers' work by not forcing them to learn a specialized templating language, according to Hibbs. Many other application-development frameworks use a language just for templates because their main programming language isn't expressive enough, noted Heinemeier Hansson.
Rails has another interface component called Builder that generates responses to XML—rather than HTML—requests, such as those used in Web services.
Clean, concise, consistent, and structured like languages such as Java, Ruby also offers the speed and ease of use of scripting languages such as PHP, according to Heinemeier Hansson.
Ruby is a powerful dynamic language, so instead of writing large amounts of code, developers can declare commands efficiently with subtle inferences via small amounts of code, he explained. Ruby can be used to write templates and conventions that make development much quicker, Heinemeier Hansson added.
Moreover, he said, with Ruby, developers can do things that generally are considered bad practice—and that other languages might make difficult—but that are the most efficient approach under certain circumstances.
A single Rails developer can do the work of an entire team using Java, and a group of Rails developers can do projects in a month that would take six months with Java, according to Boeing's Hibbs.
Bruce Tate, president and owner of J2Life, an application-development company, said that in building a start-up project for a customer, his company used 25 percent of the code and spent 10 percent of the time on configuration with Rails that it would have experienced with Java.
Tate said that if a Rails-built application turns out to be missing something, developers can simply make the needed changes to the appropriate class and plug it back into the framework. "I have seen a security-manager [component] modified [in Rails] with just 82 lines of code," he noted.
In addition, Rails is a completely integrated, full-stack environment, with all components designed to work together, according to Hibbs. This is not the case with many other development environments.
For example, Hibbs explained, very few Java frameworks provide a complete Web-application development approach. Instead, he explained, Java developers often must combine multiple frameworks, which often aren't designed to work together. They thus must spend time and money to make them work together, which takes away from the application development itself, he said.
Rails is code-efficient in part because it uses the don't-repeat-yourself principle. Rails applications generally use the same code for the same purpose throughout. And by modifying a set of code in one place, developers can also change other instances of the same code set.
In some other types of development frameworks, such as the Java-based Apache Struts, Hibbs said, designers must write an entire class for every command, each of which must be in a separate file. This creates considerable textual overhead and a proliferation of program files, he noted.
In Rails, Hibbs explained, a preprogrammed method within a controller class handles each command, which requires very little textual overhead, and all related commands can occupy the same file. This greatly reduces the amount of work and code necessary in Rails.
Rails also entails assumptions, which means that without the need for any configuration, it builds programs that automatically behave as Web applications generally behave. For example, Heinemeier Hansson noted, Rails makes the assumption that in a Web application, a database table—such as one called "cars"—will includes multiple classes of the same general type—such as "sports cars" and "SUVs."
Developers would have to configure their applications when such normal behavior isn't desired.
According to Heinemeier Hansson, many application-development approaches assume maximum user flexibility is most desirable and thus require considerable configuration to ensure that flexibility.
On the other hand, he explained, "Rails says, 'Let's make it easy for what most people need to do most of the time. Let's optimize for that scenario. And sure, let's have enough flexibility to make it possible to do something else.'"
Derailing Ruby on rails
Because it's so new, said Richard Monson-Haefel, senior analyst for application platform strategies service with the Burton Group, a market research firm, "I wouldn't use Rails for something that is mission critical."
Developers don't know yet whether Rails is sufficiently scalable. Thus, J2Life's Tate said, they should not use it for large projects in which scalability is important.
The technology also hasn't been around long enough to demonstrate whether it's secure. Tate said several e-commerce firms are examining Rails' security and have been pleased so far. However, he added, "It's still very early. We just don't know. I would call that a negative if I were securing a nuclear reactor."
"[Rails] is based on a programming language with which most developers are not familiar," noted Monson-Haefel. "Thus, the ecosystem around Ruby isn't as healthy as it is for Java. It's harder to find training, and it's harder to find tools."
According to Tate, "Ruby is a lot more dynamic [than other languages], so you have to know what you are doing with it."
Because Rails is in its early stages, no one has built integrated development environments yet. Thus, Rails tools are primarily command-line driven, requiring more manual work by developers.
Like other new technologies, said the National Research Council of Canada's Downes, Rails is evolving rapidly and not always consistently.
"Like most such code," Downes noted, "Rails relies on a foundation of numerous other applications."
"This means that upgrades in foundational code may result in instability in Rails," he said. "This was the problem I encountered."
He noted, "Ruby 1.8.3 was released and adopted by the Rails community. However, Rails breaks under 1.8.3 because Ruby developers did not test for compatibility with Rails. Also, MySQL (an open source relational database) adopted a new user-authentication system. When Rails tried to log on to MySQL using the old system, it failed. Rails was thus upgraded to adapt to the new MySQL authentication. However, this meant that it now fails on older MySQL systems."
Moreover, Downes said, "Much of the documentation I found, despite being only a few months old, was out of date and, consequently, incorrect."
Nonetheless, Tate said, developers are still willing to test the technology, but their managers are either reluctant to try something so new or want to continue using development approaches in which their companies have already invested.
Not all software experts are optimistic about Rails' future. "My reaction is that it is yet another load of hype," said Les Hatton, founder of Oakwood Computing, a software vendor and consultancy. "Why do we need yet another amazing new dynamic Web environment when half of the world's Web sites are unreliable and the rest are under continuous attack by phishers, hackers, and so on? Will Ruby on Rails help this? I very much doubt it."
The Burton Group's Monson-Haefel disagreed: "I think Ruby on Rails will do well. If it continues to be adopted at the rate it has been, a number of tools and libraries will be available to make it more broadly applicable. Its ecosystem will grow around that. I think it's going to take off really quickly with independent consultants doing projects for small- to medium-sized companies, simply because of the productivity advantage."
"Ruby on Rails or some derivative of that will become quite popular," Monson-Haefel predicted. "It's a very easy platform to work with. Most people will become very productive with it very quickly."
"After five years," Boeing's Hibbs said, "I expect Ruby on Rails to have serious penetration in the enterprise. Looking back on how long it took Java to take hold in large companies, I certainly would expect Ruby on Rails to do the same thing."
David Geer is a freelance technology writer based in Ashtabula, Ohio. Contact him at firstname.lastname@example.org.