Advanced Rails - Building Industrial-Strength Web Apps in Record Time

(Tuis.) #1
1

Chapter 1 CHAPTER 1


Foundational Techniques 1


Simplicity is prerequisite for reliability.
—Edsger W. Dijkstra

Since its initial release in July 2004, the Ruby on Rails web framework has been
steadily growing in popularity. Rails has been converting PHP, Java, and .NET devel-
opers to a simpler way: a model-view-controller (MVC) architecture, sensible
defaults (“convention over configuration”), and the powerful Ruby programming
language.


Rails had somewhat of a bad reputation for a lack of documentation during its first
year or two. This gap has since been filled by the thousands of developers who use,
contribute to, and write about Ruby on Rails, as well as by the Rails Documentation
project (http://railsdocumentation.org/). There are hundreds of blogs that offer tutori-
als and advice for Rails development.


This book’s goal is to collect and distill the best practices and knowledge embodied by
the community of Rails developers and present everything in an easy-to-understand,
compact format for experienced programmers. In addition, I seek to present facets of
web development that are often undertreated or dismissed by the Rails community.


What Is Metaprogramming?


Rails brought metaprogramming to the masses. Although it was certainly not the first
application to use Ruby’s extensive facilities for introspection, it is probably the most
popular. To understand Rails, we must first examine the parts of Ruby that make
Rails possible. This chapter lays the foundation for the techniques discussed in the
remainder of this book.


Metaprogrammingis a programming technique in which code writes other code or
introspects upon itself. The prefixmeta-(from Greek) refers to abstraction; code that
uses metaprogramming techniques works at two levels of abstraction simultaneously.

Free download pdf