Ruby On Rails Presentation

Preview:

DESCRIPTION

Ruby on Rails intro by David Quitoriano

Citation preview

Ruby on Rails

Optimized for programmer happiness and sustainable productivity

Based on Curt Hibbs' Rails presentation to the St. Louis Java Users Group (June

2006)

http://dave.quitoriano.org/csb

Overview

● What is Ruby?● What is Rails?● MVC (Model-View-Controller)● Live Demonstration (sort of…)● Agile vs. Waterfall Model● Rails Applications in Production● Q&A● Resources

What is Ruby?

A dynamic, object-oriented programming language with:● a strong focus on simplicity and productivity● Smalltalk's conceptual elegance, ● Python's ease of use and learning, and ● Perl's pragmatism.

Ruby originated in Japan during the mid-1990s and was initially developed and designed by Yukihiro "Matz" Matsumoto.

Ruby is...

InterpretedLike Perl, Python

Object-OrientedLike Smalltalk, Eiffel, Ada, Java

Rapidly Gaining Mindshare in US and EuropeOriginated in Japan, very popular there

Why Ruby?

● Easy to learn● Open source (very liberal license)● Rich libraries● Very easy to extend● Truly Object-Oriented● Excellent community● Bottom Line: write more understandable code

in fewer lines– Less code means fewer bugs

Sample Ruby Code

Code courtesy of John W. Long

Sample Ruby Code

Code courtesy of John W. Long

What is Rails?

““Rails is a full-stack framework for Rails is a full-stack framework for developing database-backed web developing database-backed web applications according to the Model-applications according to the Model-View-Control pattern.”View-Control pattern.”

www.rubyonrails.org - Ruby on Rails official site

Rails is a Full-Stack Framework

● Includes everything needed to create a database-driven web application using the Model-View-Controller pattern.

● Being a full-stack framework means that all layers are built to work seamlessly together.

● That way you Don’t Repeat Yourself (DRY).

Rails is Agile

● built-in webserver● generators – save the fingers (CRUD)● scaffold – kick-off start● plugins, libraries, tons of contributed code● native AJAX support

“leaving you to fill in the applications logic”

DHH

David Heinemeier HanssonDavid Heinemeier Hansson (28) is (28) is a Danish programmer and the creator a Danish programmer and the creator of the popular Ruby on Rails web of the popular Ruby on Rails web development framework. He is also a development framework. He is also a partner at the web-based software partner at the web-based software development firm 37signals.development firm 37signals.

In 2005 he was recognized by Google In 2005 he was recognized by Google and O'Reilly with the Hacker of the and O'Reilly with the Hacker of the Year award for his creation of Ruby Year award for his creation of Ruby on Rails.on Rails.

Last July 2006, Business 2.0 ranked Last July 2006, Business 2.0 ranked him 34th among '50 people who him 34th among '50 people who matter now'.matter now'.

Source: Wikipedia Source: Wikipedia (http://en.wikipedia.org/wiki/David_Heinemeier_Hanss(http://en.wikipedia.org/wiki/David_Heinemeier_Hansson)on)

Principles of Ruby

Japanese Design Aesthetics Shine Through

● Focus on human factors

● Principle of Least Surprise

● Principle of Succinctness

Relevant because these principles were followed closely by the designer of Rails, David H. Hansson

Scandinavian Design Aesthetic

Philosophies● Less Code

– Requires fewer total lines of code than other frameworks spend setting up their XML configuration files.

● Convention over Configuration– Rails shuns configuration files in favor of

conventions, reflection and dynamic run-time extensions.

● Configure your application by making it– Your code and database schema are the

configuration!– No compilation phase

● Make a change, see it work.

Traditional Applications

● Browser directly accesses page.– Does not centralize control– No content/style separation– Easy and fast to produce– Difficult to maintain

MVC Applications

● Browser accesses a “controller”– Centralizes control– Clean separation of content/style– More involved to produce– Easier to maintain and expand

Design Pattern

● A pattern that has been developed to help programmers cope with common problems.

● Blueprints on how to construct something.

Typical Bakery Interaction

● Request a tasty treat from the baker

http://www.pixpatisserie.com/

Baker responds with your treat

http://www.pixpatisserie.com/

Bakery Flow

MVC Diagram

All Together Now

http://wiki.rubyonrails.org/

Rails and MVC

● Model (ActiveRecord) – Maintains the relationship between Object and

Database– Handles validation, association, transations, and

more…– Does not completely insulate the developer from

SQL

Rails and MVC

● View (ActionView) – Script-based templating system (like JSP, ASP,

PHP, etc.)– Tight controller integration– Reusable components– Integrated, easy to use Ajax support.

Rails and MVC

● Controller (ActionController) – Reflection ties actions to methods– Tight view integration– Filters, layouts, caching, sessions, etc.

Rails Demonstration

Testing Rails

● Rails has great testing framework ‘baked in’ the framework– Test stubs created when code is ‘generated’.

● Unit to test models. – test/unit

● Functional to test views/controllers– test/functional

● Fixtures– Supply test data (yaml)

Unit Testing

• Separate ‘test’ database is used.

• Fixtures supply data

• Variety of ‘assert’ statements.

http://rspec.info/

Database Support

● Supported Databases– MySQL– PostgreSQL– SQLite– SQL Server

● Coming Soon– Oracle– DB2– Firebird– more…

Server Configurations

– WEBrick ● Built-in to Rails● Good development environment

– Apache/CGI● Easy to set up, but slow

– Apache/mod_ruby● Ruby interpreter per Apache process

– Apache/mod_fastcgi● Pool of Ruby processes

– Lighttpd● Built-in fastcgi support● Small footprint, high performance

Waterfall Model

Agile Programming

Agile Manifesto

We are uncovering better ways of developing software by doing it and

helping others do it. Through this work we have come to value:

Individuals and interactions over processes and

tools

Working software over comprehensive

documentation

Customer collaboration over contract

negotiation

Responding to change over following a plan

Get something real up and running quickly

Running software is the best way to build momentum, rally your team, and flush out ideas that don't work. It should be your number one priority from day one.

It's ok to do less, skip details, and take shortcuts in your process if it'll lead to running software faster. Once you're there, you'll be rewarded with a significantly more accurate perspective on how to proceed. Stories, wireframes, even html mockups, are just approximations. Running software is real.

With real, running software everyone gets closer to true understanding and agreement. You avoid heated arguments over sketches and paragraphs that wind up turning out not to matter anyway. You realize that parts you thought were trivial are actually quite crucial.

http://gettingreal.37signals.com/ (IM Students required reading)(IM Students required reading)

Development Metrics

Basecamp– Launched in early 2004

● “Tens of thousands of users across 50 countries” ● 2 man-months of programming by a single developer

(the Rails author).● 4,000 Lines of Code.

• Server details● One dual 2.2GHz Xeon,

2G RAM.

Development Metrics

Backpack– Launched in May 2005

● http://www.backpackit.com● Makes very heavy use of Rails’ built-in Ajax support

for an extremely responsive user interface.

Development Metrics

43 Things

“With Ruby and Rails we went from nothing to a live site in about 3 months. Only one person in the company had any prior Ruby experience (me) and he spent half his time playing sysadmin.

“In the 2.5 months since launch we’ve done major rewrites of two of our core codepaths, added 3 large features and have done exploratory programming in two other directionswith only 5 developers.

“Our codebase is hanging in at justunder 7,000 lines of productionRuby…”

● As of February, 2005:– 9,000 registered users – 200,000 hits per day

Development MetricsBellyButton.de

– Launched in February 2005● An ecommerce site marketing pregnancy related products.● 2 developers and one graphic designer.● 2,400 Lines of Code.● 5 man-months of

development time.

Development MetricsSnowDevil.ca

– Launched in February 2005● An ecommerce site marketing snowboards and related gear.● 2 developers.● 6,000 lines

of code.● 4 months of

development time.

Development Metrics

StoryCards– Web app to support XP-style development by Jim

Weirich– http://onestepback.org:3030/

– 1,250 Lines of code– 8 hours of

development time

Rails Testimonials“Rails is the most well thought-out web development framework I've

ever used. And that's in a decade of doing web applications for a living. I've built my own frameworks, helped develop the Servlet API, and have created more than a few web servers from scratch. Nobody has done it like this before. That's not to say they got it all right. It's by no means "perfect". I've got more than a few nits and picks about how things are put together. But "perfect" isn't the point. The point is that it gets you up and going fast and has plenty of depth to keep you going. And Rails does that very well.”

- James Duncan Davidson was the creator of Apache Tomcat and Apache Ant and was instrumental in their donation to the Apache Software Foundation by Sun Microsystems . While working at Sun, he authored two versions of the Java Servlet API specification as well as the Java API for XML Processing.

“I can only show you the door. You're the one that has to walk through it.”

- Morpheus, The Matrix, 1999

In closing

● It's not the language. It's the programming principle. Simply put, “It's not the HOW, it's the WHY.”

● Commitment to open source technologies (Java/Ruby/Phython)

● Encourage a “Framework” mindset ● Emphasis on application testing● Creators vs Followers ● Innovators vs the Wait-and-see● Bleeding edge vs software that suck

Resources● Ruby

– Main Ruby Site• http://www.ruby-lang.org/en/

– One-Click Ruby Installer for Windows• http://rubyinstaller.rubyforge.org/

– RubyForge – open source project repository• http://rubyforge.org/

● Rails– Main Rails Site

• http://www.rubyonrails.org/– Rails Tutorial (2 part series)

• http://www.onlamp.com/pub/a/onlamp/2005/01/20/rails.html

• http://www.onlamp.com/pub/a/onlamp/2005/03/03/rails.html

– Agile Web Development with Rails (first Rails book)• http://www.pragmaticprogrammer.com/titles/rails/

– Ajax on Rails• http://www.onlamp.com/