Datasheet

The following fact might not surprise you at all. What separates Rails from
Struts and other frameworks is agility. Other frameworks used to solve the Web/
database problem are heavy and rigid. Development in these other frameworks
is slow and formal. In comparison, Rails is lightweight and nimble.
Author and practitioner Curt Hibbs claims that you can write a Rails applica-
tion in one-tenth the time it takes to write the same application using a
heavyweight framework. Many people challenge this claim, but the fact that
Hibbs is willing to make the claim says something important about Rails.
Rails is built on two solid principles: convention over configuration, and
Don’t Repeat Yourself (DRY).
Convention over configuration
A Web application consists of many parts, and you can go crazy connecting
all the parts. Take one small example. You have a variable named
picture
in a computer program, and you have a column named image in a database
table. The computer program fetches data from the
image table column and
stores this data in the
picture variable. Then the program performs some
acrobatics with the
picture variable’s data. (For example, the program dis-
plays the picture’s bits on a Web page.)
One way to deal with an application’s parts is to pretend that names like
picture and image bear little relation to one another. A programmer stitches
together the application’s parts using a
configuration file. The configuration
file encodes facts such as “variable
picture reads data from column image,”
“variable
quotation reads data from column stock_value,” and “variable
comment_by_expert reads data from column quotation.” How confusing!
With dozens of names to encode at many levels of an application, program-
mers spend hours writing configuration files and specifying complex chains
of names. In the end, errors creep into the system, and programmers spend
more hours chasing bugs.
Rails shuns configuration in favor of naming conventions. In Rails, a variable
named
image matches automatically with a column of the same name in the
database table. A variable named
Photo matches automatically with a table
named
photos. And a variable named Person matches automatically with a
table named
people. (Yes, Rails understands plurals!)
In Rails, most configuration files are completely unnecessary. You can create
configuration information if you want to break Ruby’s naming conventions.
But if you’re lucky, you seldom find it necessary to break Ruby’s naming
conventions.
18
Part I: Nuts and Bolts
05_081204 ch01.qxp 11/30/06 11:09 PM Page 18