45
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

Ruby On Rails Presentation

Embed Size (px)

DESCRIPTION

Ruby on Rails intro by David Quitoriano

Citation preview

Page 1: Ruby On Rails Presentation

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

Page 2: Ruby On Rails Presentation

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

Page 3: Ruby On Rails Presentation

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.

Page 4: Ruby On Rails Presentation

Ruby is...

InterpretedLike Perl, Python

Object-OrientedLike Smalltalk, Eiffel, Ada, Java

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

Page 5: Ruby On Rails Presentation

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

Page 6: Ruby On Rails Presentation

Sample Ruby Code

Code courtesy of John W. Long

Page 7: Ruby On Rails Presentation

Sample Ruby Code

Code courtesy of John W. Long

Page 8: Ruby On Rails Presentation

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

Page 9: Ruby On Rails Presentation

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).

Page 10: Ruby On Rails Presentation

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”

Page 11: Ruby On Rails Presentation

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)

Page 12: Ruby On Rails Presentation

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

Page 13: Ruby On Rails Presentation

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.

Page 14: Ruby On Rails Presentation

Traditional Applications

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

Page 15: Ruby On Rails Presentation

MVC Applications

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

Page 16: Ruby On Rails Presentation

Design Pattern

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

● Blueprints on how to construct something.

Page 17: Ruby On Rails Presentation

Typical Bakery Interaction

● Request a tasty treat from the baker

http://www.pixpatisserie.com/

Page 18: Ruby On Rails Presentation

Baker responds with your treat

http://www.pixpatisserie.com/

Page 19: Ruby On Rails Presentation

Bakery Flow

Page 20: Ruby On Rails Presentation

MVC Diagram

Page 21: Ruby On Rails Presentation

All Together Now

http://wiki.rubyonrails.org/

Page 22: Ruby On Rails Presentation

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

Page 23: Ruby On Rails Presentation

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.

Page 24: Ruby On Rails Presentation

Rails and MVC

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

Page 25: Ruby On Rails Presentation

Rails Demonstration

Page 26: Ruby On Rails Presentation

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)

Page 27: Ruby On Rails Presentation

Unit Testing

• Separate ‘test’ database is used.

• Fixtures supply data

• Variety of ‘assert’ statements.

http://rspec.info/

Page 28: Ruby On Rails Presentation

Database Support

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

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

Page 29: Ruby On Rails Presentation

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

Page 30: Ruby On Rails Presentation

Waterfall Model

Page 31: Ruby On Rails Presentation
Page 32: Ruby On Rails Presentation

Agile Programming

Page 33: Ruby On Rails Presentation
Page 34: Ruby On Rails Presentation

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

Page 35: Ruby On Rails Presentation

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)

Page 36: Ruby On Rails Presentation

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.

Page 37: Ruby On Rails Presentation

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.

Page 38: Ruby On Rails Presentation

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

Page 39: Ruby On Rails Presentation

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.

Page 40: Ruby On Rails Presentation

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.

Page 41: Ruby On Rails Presentation

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

Page 42: Ruby On Rails Presentation

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.

Page 43: Ruby On Rails Presentation

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

- Morpheus, The Matrix, 1999

Page 44: Ruby On Rails Presentation

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

Page 45: Ruby On Rails Presentation

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/