Oct 18, 2009 - IBM

granddetourfannieInternet και Εφαρμογές Web

2 Φεβ 2013 (πριν από 5 χρόνια και 5 μήνες)

167 εμφανίσεις


Chapter 1

Introduction to the Ruby language
and the Rails framework

1.1 A brief history of Ruby and Ruby on Rails

When Ruby and Ruby on Rails became popular, web development was in a middle of a
crisis. Ruby on Rails developed in response to the turmo
il of the
status quo
. That's not to
say that a crisis is always a bad thing: it generally means a transition to something better,
and although the crisis is by no means over, Ruby on Rails has played a significant role in
reducing its severity.

In this cha
pter I will go over the main components of the crisis, analyzing Symptoms,
Context and Causes. It will mainly focus on mainstream technologies like Java, PHP and

1.1.1 Symptoms

These are the symptoms of the crisis:

Hundreds of frameworks

None of them

is in a position to dominate (as Struts did), which is good in that it
breaks the consensus. Instead of focusing on solving most of the application
concerns and possibilities, new frameworks get developed that don't address the
real problems found in Web

There is no innovation, just copy

These new frameworks are just copies of previous ones containing more or less of
their features, but none of them can really be described as innovative.

Complexity is increased

Most of the functional behavio
rs of Web Application are simple CRUD, but
Architectures and Web Framework hinder development by increasing complexity.
They foster the duplication of code as a defining element in media such as Java

Code, XML, DDL, HTML, and this in turn leads to the over
use of hierarchical
styles, creating and isolating layers insensibly.

JVM has been opened to support new languages

Sun decided to open the Java Virtual Machine for executing new languages other
than Java.

1.1.2 Context

Meanwhile, other developments
were occurring in the industry (I shall explain each of

Agile Methodologies adoption

The Software Industry began adopting Agile Methodologies in order to improve the
quality of software by involving users sooner rather than later and adopting

rather than following a contractual negotiation.

Dynamic Languages becoming popular

Adoption of this kind of language was on the increase due to developmental
productivity and to the ease of applying advanced design and programming

Rich Inter
net Applications

Traditional Web Application started a transition to Rich Internet Application (aka
RIA) in order to keep the benefits of thin clients but also to enhance the user
experience by adding new usability items. Of course it also inherits certai
disadvantages, such as resource consumptions.

Service Oriented Architecture is becoming popular

In the Enterprise Architecture domain, SOA has become the first selected
Architectural Style for integrating Web Applications. Software vendors developed
tion stack of products following standards such as WSDL, SOAP, WS

1.1.3 Causes

Problems caused by this web
development crisis:

Low productivity

Extra cost for maintaining software

To much effort to set up a development environment


1.2 Ruby

uby is a language created by Yukihiro Matsumoto (also known as “Matz”) in Japan during
the mid
1990s. It’s a multi
paradigm language based on a dynamic
type system with
automatic memory management. It was first published at the end of 1995, and the main
atures included were object
oriented design, classes with inheritance, mixins (traits),
iterators, closures, exception
handling, and garbage
collection. Ruby is a dynamic
language that gained its high reputation through the great features it poss
essed. According
to Matz, he decided to create his own language because he dreamed of a scripting
language more powerful than Perl and more object
orientated than Python.

It was created with the aim of generating a brand new language able to transform the
developer experience into one of greater productivity and much more fun. He emphasized
a human
oriented design, and did not focus upon the requirements of the machine. He
decided to embrace the concept of “beautiful code” which promotes readability,
tanding and conciseness, enabling us to keep things simple.

1.3 Rails

We shall give just a brief description here, though you will find a more detailed explanation
in the following chapters. Rails is a web
development framework, developed in Ruby, and
d on the MVC model. It is the bedrock of Ruby's features that makes it possible to
develop, deploy and maintain higher
quality web applications quickly and with greater

The framework was created by David Heinemeier Hansson (also known as “DHH”), whil
he was working on Basecamp, a project
management tool developed by 37 Signals. It was
first released as open source in July 2004 and was the starting point for a very active
community. Finally on December 14

2005 a full version was delivered with the h
elp of the
members of that community.

At first sight, Rails is built in with scaffolding feature, a web server called WEBrick, a
special build system called Rake and a selected set of libraries of Javascript, like
Script.aculo.us and Prototype. In the begi
nning it utilized SOAP for web services but
nowadays it’s based on RESTful interfaces. One of its most interesting characteristics is
the ActiveRecord package which provides an object
oriented mapping system for database

1.2.1 Rails principl

Rails philosophy is founded on two main principals:


“Do not repeat yourself” (DRY) principal


“Convention Over Configuration” (CoC) principal

The DRY acronym stands for “Do not Repeat Yourself” and is based on the idea that every
piece of knowledge in a

system should be expressed in one place only. This helps
programmers avoid smaller changes in many different parts of the application. Thus there
will be fewer places to make code changes due to DRY and they will be localized and
expressed accurately and
concisely. Now your code won’t be error
prone and the impact of
any change in your application will be minor.

On the other hand, the CoC acronym stands for “Convention Over Configuration”. In this
direction, Rails provides default writings in order to make

it possible to tie up your
application, making configuration one of the simplest steps in the framework. Just follow
the convention and you can easily write your first Rails application. Finally you will use less
code while forgetting about configuration

Rails is also Agile: it tries to apply the concepts mentioned in the Agile manifesto. It’s about
people and interaction between them. It’s aimed at small groups and built around chunks of
Ruby code. This results in a more transparent process and giv
es customers a better
understanding of the important role of developers. Rails makes it easier to document but is
by documentation. It is a framework entrusted to deliver software early during
the development cycle. And last but not least, the i
dea that the software should be able to
respond to changes is central to its methodology. Early deliveries require further changes
in future and Rails was designed to be prepared for it.

1.4 Career path & job opportunities

1.4.1 Learning Roadmap

When a new

employee is hired for a Ruby project inside IBM Argentina Global Delivery
Center he/she must follow a predefined Ruby Learning Roadmap which consists of:


Introduction and Initial Setup

The objective of this phase is to give a quick and short

but impress

to Ruby and RoR, including a Live Demo.
IDE setup, both Eclipse with Aptana and
Netbeans. Irb (Interactive Ruby). Ruby programs. Ri.


Ruby for dummies

The objective of this phase is to learn all of Ruby, it will cover items like: objects
classes, control access, variables and methods. Data types, expressions and flow
control: numbers and strings, arrays and lists, hashes, control structures, expressions
and assignments, blocks and iterators, ranges, closures. Object Oriented Concepts:
tensions, method overloading, reflection, encapsulation, polymorphism, inner
classes, modules, namespaces and mix
ins. Projects and libraries: including other
file/directory source code, standard library, net/http, OpenStruct and RubyGems
(packaging). More

of Ruby: documenting with RDoc, error and exception handling,
ruby debugger and threads.

In essence it follows the free book “Programming Ruby, The Pragmatic Programmer's


Ruby Patterns

Template Method. Strategy. Observer. Composite. Iterator. Com
mand. Adapter. Proxy.
Decorator. Singleton. Factory. Builder. Interpreter


Ruby on Rails

Once a developer has a good understanding of Ruby, Ruby on Rails concepts can start:
Rails Architecture: MVC and Rails project structure. Rake. Generators and Scaffold.

Migrations. ActiveRecord


Agile Rails Development

The last phase in the roadmap describes how a Rails application is approached, and
covers such concepts as Agile Methodologies Introduction, Behavior Driven Development
with rSpec (including TDD concepts),
usage of source control (model, centralized and
distributed), Build Automation and Continuous Integration with Capistrano. Pre

Even though most of Ruby developers come from the Java world, our experiences in
implementing the Ruby roadm
ap indicate that Developers from a Smalltalk language
background understand Ruby concepts more easily and are more able to program real
oriented code, thereby maximizing the use of a dynamic language like Ruby.

1.4.2 Ruby on Rails development certif
ications and accreditations

As with other technologies there is a discussion at present around the extent to which
certification or accreditation determines one's real abilities as a Ruby or Ruby on Rails
developer. In the case of this technology, good de
velopers are those that can take design
decisions, implement them adhering to Rails frameworks and

doing it!

In general, current exams or certification do not take this principle into account, favoring the
evaluation of specific Ruby or Ruby on Rails

knowledge rather than pragmatic design skills.
This approach measures neither aptitude for design nor passion for the work and therefore
limits the value of such exams currently offered by

Ruby on Rails.

1.4.3. Job Opportunities and Job Posting

It is not the goal of this book to discuss Ruby on Rails' popularity; that can be seen and
everywhere, as illustrated by the following
Google Trends graph.

It's popularity,
however, poses the following question: is it possible to be a satisfied Ruby on Ra
developer and at the same time grow professionally and economically? In response we
refer to Ruby's use in two models in the industry:

Development of Enterprise Applications
. You can be hired to by a company to
develop custom web
based applications.

. You can start your company or can be hired by a new company to
develop new product


shows a nice graph of the Trend of Ruby on Rails jobs postings.

1.5 Ruby and Ruby
on Rails

The Rails phenomenon exploded because it had strong background concepts based on
Ruby as defined by Matz. Furthermore, that Ruby contained its own principals led to its
being one of the most widely adopted web frameworks. So the question now is wh
y? Well,
simply because Ruby is:


A modern language


An Object Oriented Scripting language


Very Concise


Excellent to express ideas more naturally

As mentioned before, Ruby makes use of modern techniques that every good professional
would willingly apply. It’
s an object
oriented scripting language so you can easily and
quickly develop small but powerful scripts from an OO perspective. As it is a dynamic
language it is concise and conducive to writing fewer lines of code. It’s also possible to

express ideas nat
urally because it’s closer to human language. It’s easy to write but it’s
also easier to read. As you won’t waste time in trying to analyze how it was developed or
where bugs might be found, it is advantageous not only when coding begins but throughout

maintenance phase of the project.

So Ruby offers a simplicity and potential which leads to a more productive experience
when using Rails. Besides which it improves the way communication flows at every corner
of the project. Consider that by providing a co
mmon language to all team members,
developers are better understood by their leaders and by their customers.

1.5.1 Java on Rails?

Thus, once you have experienced how great it is to work with Ruby on Rails, you must
regard “Java on Rails” as a bad joke. Jus
t think, Java is an amazing language and it has
been also for many of us our first love, but let's be honest: it’s not perfect for every project.
As individual projects contain many characteristics, we are not able to deliver strictly Java
solutions for al
l of them. We must think about the requirements, developers' skills and the
context as a whole.

Furthermore Java is a grown
up language. It will undoubtedly keep growing for a while, but
it is already established and at times may lack the flexibility that
a more dynamic language
like Ruby provides. So Java might be too old and too rigid to compete with the youthful,
flexible framework that Rails is.

Another important factor is that many Java followers have recently moved away from their
frameworks to tackl
e problems in productivity and to reduce the required complexity of
such methods. For them, Rails was the new framework that provided most options and
helped to reduce the complexity of integration.

1.6 Community

Considering the context as a whole, by the

time Rails' popularity rose, we could already
see a series of participating factors:


More skills were required to develop web applications in the actual context.


Professional developers need to be able to apply modern techniques without extra


h increment of the complexity of the solutions used by different platforms.

Nowadays, software development forms part of a polyglot world. Developers' skills are
unlikely to reach their maximum potential. Each element of a single application may employ
a v
ariety of different languages. During the crisis this had reached such a point that no one
developer might have used them all to their full proficiency. In this time, Ruby was

beginning to grow, bringing with it change and fresh winds. Its brightest featur
es made it so
particularly useful in the building of the Rails framework that Developers who had
previously found themselves frustrated using tools and technologies like .NET and Java to
develop web applications adopted the new methodology eagerly. No matt
er which platform
developers came from, Rails was the simplest solution and allowed developers to liberate
themselves from the onerous task of integrating separate and diverse components.

However, Rails' wide
scale adoption amongst developers principally o
wes to its being built
around a particular philosophy. Its principals and concepts offer professionals personal
satisfaction. It requires no extra effort in applying concepts frequently employed by Java
programmers, such as patterns, testing techniques, AJ
AX, RESTful web services, etc.
Rails works by aiding the definition of new standards and integrating each new concept
from the technology Web 2.0.

As the complexity of solutions grows, individual understanding of projects becomes
clouded and consequently
communication between team
members becomes noisy and
incomprehensible. This is often reflected in the use of integration frameworks which only
encourage and accumulate what Rubists call “ugly code”.

Rails is popular essentially because it’s fun, very easy
to get on with and because it allows
us to provide web developments of higher quality.

1.7 Exercises

No exercises

1.8 Summary


1.9 Review Questions