Explainer: Ruby on rails

The programming language Ruby has been around since 1993. Initially popular in Japan, its use has been growing and widening. Ruby got a big boost in 2004 with the release of a new programming environment called Rails that was built around Ruby. Before discussing Rails, let's first examine Ruby and see what makes it different from other languages.

Ruby

Ruby is a pure object-oriented, open-source programming language with a very clean syntax that one writer has said "combines Smalltalk's elegance, Python's ease of use and Perl's pragmatism." An interpreted scripting language, Ruby is as useful for creating small ad hoc scripts as it is for full-scale applications. Using a direct-execution model and dynamic typing, Ruby lets you develop code incrementally; in most cases, you can add a feature and then try it immediately. Ruby programs are usually shorter than their Perl, Python or C++ counterparts.

Ruby's creator, Yukihiro Matsumoto, has said he wanted a language that would make him more productive and at the same time be fun to use. In fact, this desire for fun in programming is probably Ruby's biggest single point of differentiation from any other language. When one first starts reading the Ruby literature, it's easy to think that it's a boutique language with a cultlike following of near-fanatic users. But remember that Perl, PGP and Python started out in much the same way.

Every language is designed with specific purposes: ease of coding; compactness of code; readability; speed of execution; orientation for specialized situations such as text processing, database handling or numerical computation. Even so, with most languages that are Turing-complete, you can pretty much do anything you need; the practical differences from one to another will be in the areas of form, style, size, ease of use or maintainability. In an online interview, Matsumoto said, "Languages do differ -- but the differences are limited. For example, Python and Ruby provide almost the same power to the programmer."

Matsumoto designed Ruby with a minimum of "apparatus" and excess verbiage, such as headers and extensive requirements for variable and class declarations. Ruby's syntax is such that once you're familiar with its vocabulary and style, you can read many lines of code in something like natural spoken language, making programs much easier to understand and maintain.

Matsumoto has said he wants to concentrate on the specific things he's trying to do at the moment, not on the arbitrary rules of the language. Ruby eliminates the need to start out each program with long statements declaring structures and variables.

Like Perl, Ruby has features that make it easily adaptable to processing text files and to systems management tasks. You can add methods to a class, or even to an instance during runtime, so that you can have an instance of one class behave differently from other instances of the same class. Also like Perl, but quite different from Python, Ruby lets you code things in many ways, thus it can appeal to programmers with very different styles and personalities.

Rails

Rails is a full-stack, open-source programming framework implemented in Ruby and designed for writing database-oriented real-world Web applications quickly and easily. It was created by David Heinemeier Hansson, a Danish college student, based on a project management tool he'd written called Basecamp. Ruby on Rails was released to the public in July 2004.

By full-stack framework, Hansson means that all layers are built to work together so that you don't repeat yourself (DRY) and you can use a single language from top to bottom. Everything in Rails is written in Ruby. To achieve DRY, Rails relies on a couple of guiding principles.

The first is less software, meaning you write fewer lines of code. Keeping code small speeds development and makes for fewer bugs, and it makes code easier to understand, maintain and enhance. One feature of Ruby that contributes to writing less code is that it assumes that the framework itself can and should handle metadata.

The second is the principle of convention over configuration, meaning that Rails doesn't use configuration files, relying instead on some simple programming conventions that let it figure out what it needs to know by using information already contained in the application code and the database that's running. According to Hansson, "this means the end of XML files telling a story that has already been told in code. It means no compilation phase: Make a change, see it work."

Join the newsletter!

Error: Please check your email address.

More about ApacheBusiness ObjectsCGIGatewayMySQLOraclePGPSpeed

Show Comments

Market Place