ruby on rails - rochester k linux user group
TRANSCRIPT
Ruby & Ruby on Rails
Jos de LeonK-LUG July 13, 2006
About Me
Jos de Leon
Career software developer, Problem-Solver by nature
Obsessed with Finding the best way or best approach
Good storyteller
Interests:
Object-oriented development
User-experience, including developers
Best practices - what's worked well for others
Outside: pro basketball/sports, comics
Email: [email protected]
About This Talk
History of Ruby & Rails
About Ruby
About Software Best Practices
How Rails Embodies Best Practices
Demos
RailsConf 2006
History of Ruby on Rails
History of Ruby
History of Rails
History of Ruby
Created by Yukihiro Matz Matsumoto in Japan, 1995
Inspired by Perl, LISP, and Smalltalk
Gained popularity outside Japan around 2000, when Programming Ruby (1st ed) was published by Thomas and Hunt
History of Rails
Conception of David Heinemeier-Hansson
Based on work derived from Basecamp, a web-based project-management application
Extracted as a distinct framework, Summer 2004
1.0 release in December 2005
Rails is a full-stack framework for developing database-backed web applications according to the Model-View-Control pattern.
About Ruby
Understanding Rails requires understanding Ruby
Ruby is a multi-paradigm, interpreted programming language:
Imperative
Object-oriented
Functional
Familiarity with Perl, Smalltalk, Java, LISP, C++ will be an asset
About Ruby
Strong text-processing and regular-expression capabilities on a par with Perl
O-O/functional properties of Ruby allow you to write programs in as natural a language as spoken language
Ruby programs tend to be readable
Ruby has strong collections facilities
Ruby is a scripting-language
Programs can be developed in an incremental, interactive style with fast turnaround
About Best Practices
Best thing about Rails: Embodies and enforces best practices and strong principles in designing software
Frameworks Are Extractions
Rails is based on a successful web-based application, Basecamp
Consistently repeated motifs and patterns: extracted to create the basis for a framework
Drawn from real-life usage and experience
Opposes Big Design Up-Front (BDUF) approach to framework building
BDUF often leads to many libraries that few find useful
Active Record Pattern
Maps rows in a database to objects in an application
Database fields are mapped to object attributes
Add smart operations for an object to interact with a database
4 basic operations:
CREATE (INSERT)
RETRIEVE (SELECT)
UPDATE (UPDATE)
DESTROY (DELETE)
Model-Controller-View
Separation of:
Data (Model)
Operations on Data (Controller):
Data manipulation
Data presentation
Presentation of Data (View)
Test-Driven Development
Rails encourages you to write your tests as you develop
Create tests exercising one facet of your application:
Unit Tests: Essential operations on a single model
Functional Tests: Essential operations between a controller and model
Integration Tests: Interactions between several controllers and models (referring to Use-Cases)
Other Best Practices
Emphasize Simplicity:
Principle Of Least-Surprise (POLS) AKA Law Of Least Astonishment (LOLA)
Do the simplest thing that could possibly work
Enable Refactoring
Don't Repeat Yourself (DRY)
Convention Over Configuration
Handle most common cases most easily, often by default
How Rails Embodies Best Practices
Demo: Simple contact list
Strong application structure created for you
Ruby code is used at every level of development in the Rails framework:
DB creation and schema management (Migrations)
Build maintenance (Rake Tasks)
URL routing (Routes)
Content serving (Webrick, Mongrel)
How Rails Embodies Best Practices
Rails presents a ready-to-use MCV architecture:
Model: ActiveRecord
Controller: ActionController
View: ActionView
ActionController includes controller equivalents (user actions) for ActiveRecord CRUD operations
ActionView can generate output for different media thru Ruby code:
RHTML: Plain text/html
RXML: XML, for Web Services (ActionWebService)
RJS: Javascript for AJAX
Other Rails Features
Rails supports sub-frameworks for:
Testing
AJAX (several popular Javascript libraries are included)
Web services
Email (ActionMailer)
Rails Applications
RadiantCMS
Blogging Engines:
Typo
Instiki (Wiki engine)
E-Commerce Tools:
RightCart (embedded shopping cart)
Shopify (hosted on-line stores)
Rails vs Other Frameworks
Rails (and others) are a reflection of Agile Development techniques
Favored over bloated Enterprise solutions (JEE)
Covers sweet spot of web applications: web front-ends for a database
Rails competes with other frameworks:
Python: Django, TurboGears
Java: JEE stack, HSE, Trails, Grails
PHP, .NET
Rails vs Other Frameworks
TurboGears and Java frameworks: combinations of existing products/projects:
SQLObject (model) CherryPy (view/controller) for TurboGears
Mix of Hibernate/iBatis/Spring (model/controller) Tapestry/Echo2/Spring MVC (view) etc. for Java/JEE
Django very close in philosophy of design with Rails
Agile techniques and practices worked into other technology stacks (.NET)
Ruby as a language has a lot going for it
Demo
Garage Invoicing Application
Componentized approach
Techniques for chaining views and models
A little AJAX
Productivity gains, especially over Java
C/C++
Java/JEE
Ruby/Rails
RailsConf 2006
Application Deployment: Capistrano
Enhanced Scaffolding (AJAX): Streamlined
Generalizing CRUD Beyond Models: ActiveResource
Streamlined
Scaffolding on Steroids
Quickly generate an AJAX interface, deriving relations from ActiveRecord Model specifications
ActiveResource
CRUD Operations can be applied to any resource, not just databases
"What if the whole world could be modeled under the constraints of CRUD?"
Extend CRUD to form basis of Resource-Oriented Architecture (objects that provide CRUD Services)
Finding Out More
Ruby Language: http://www.ruby-lang.org
Ruby On Rails: http://www.rubyonrails.org
Pragmatic Programmers: http://www.pragmaticprogrammer.com
Martin Fowler: http://www.martinfowler.com
DHH: http://www.loudthinking.com
37Signals: http://www.37signals.com
Streamlined: http://streamlined.relevancellc.com
Finding Out More
Other resources:
http://www.ruby-doc.org
http://www.rubyforge.org (Sourceforge for Ruby)
http://www.rubyinside.com
http://www.radiantcms.org
http://www.jadedpixel.com (Shopify, Typo)
Finding Out More
Books (Pragmatic Programmers):
Programming Ruby (2nd Edition) 0974514055
Agile Web Development on Rails (2nd Edition) 097669400X
CRUD Create Retrieve Update DELETE
Database (SQL) INSERT SELECT UPDATE DELETE
HTTP POST GET PUT DELETE
Life Birth Learning Teaching Death
???Page ??? (???)07/12/2006, 21:45:38Page /