SlideShare a Scribd company logo
When to use Ruby on Rails?

        Sytse Sijbrandij
       sytse@dosire.com
Contents
• Ruby
  – What is it?
  – Advantages
  – Disadvantages
• Rails
  – What is it?
  – Advantages
  – Disadvantages
• When to use it
• Reusable best practices
                               Ruby Beach, Washington, U.S.
                                      Kevin Mc Neal
What is Ruby?
• A scripting language more powerful than
  Perl and more object-oriented than Python.
• Invented in 1993 with inspiration from Perl,
  Phyton, Smalltalk, Eiffel, Ada, and Lisp.
• Designed for programmer productivity and
  joy instead of machine efficiency.
• Follows the principle of least surprise, the
  language should minimize confusion.
                                               Yukihiro 'Matz' Matsumoto
• It's easy to work with and to love Ruby.                Ruby's Architect
Ruby Advantages
    Elegant
•
    Powerful
•
    Readable
•
    Concise
•



                     Ruby and Diamond ring
                         R. M. Rayner
describe Bowling do
                               before(:each) do

     Ruby is                     @bowling = Bowling.new
                               end


     Elegant                   it quot;should score 0 for gutter gamequot; do
                                 20.times { @bowling.hit(0) }
                                 @bowling.score.should == 0
                               end
                             end

class NewBowlingGame extends PHPSpec_Context
{
    private $_bowling = null;
    public function before()
    {
        $this->_bowling = new Bowling;
    }

    public function itShouldScore0ForGutterGame()
    {
        for ($i=1; $i<=20; $i++) {
            $this->_bowling->hit(0);
        }   $this->spec($this->_bowling->score)->should->equal(0);
    }
}
Ruby is Powerful
  • Object-oriented (everything is an object)
  • Dynamic (duck typing)
# Open Ruby's Time class and add a method
class Time
  def yesterday
    self - 86400
  end
end

today = Time.now # => Thu Aug 14 16:51:50 +1200 2008
yesterday = today.yesterday # => Wed Aug 13 16:51:50 +1200 2008
Ruby is Readable
• The code comments itself
• Leads to better naming practices
# An example example function for a photo camera program
def shutter_clicked
  capture_image if @camera.on? and @camera.memory_available?
end
Ruby is Concise
• Very expressive language
• Less lines of code, higher productivity
-199.abs                                              # 199
quot;ruby is coolquot;.length                                 # 12
quot;Your Momquot;.index(quot;uquot;)                                 #2
quot;Nice Day!quot;.downcase.split(//).sort.uniq.join # quot; !acdeinyquot;

say = quot;I love Rubyquot;
say['love'] = quot;*love*quot;
5.times { puts say }
=> quot;I *love* Rubyquot; quot;I *love* Rubyquot; quot;I *love* Rubyquot; quot;I
*love* Rubyquot; quot;I *love* Rubyquot;
Ruby Disadvantages
• Ruby is Slow
• Ruby is New




                  Ruby Fails Falls, Lookout Mountain, U.S.
                                   Oscar & L
Ruby is Slow
• About 10x slower than Java, 2x slower than PHP




               All benchmarks, x64 Ubuntu, Intel Q6600 Quad
                   Computer Language Benchmarks Game
Ruby is New
• Not many developers or customers
• No common IDE
  – Most coders use the Mac text-editor Textmate
  – IDEs: RadRails, RubyMine, 3rd Rail, Netbeans
• No common application server
  – Passenger's Apache module has momentum
Evolution to web frameworks
                                  From 1990 to 2009
Time


                   Static          Dynamic                Integrated
Type of site

                Marketing       Front office          Back office
Business role
                • Brochure      • Communication       • Quotations
                • Advertising   • Ordering            • Fulfillment
                                • Mailings            • Legacy systems
Tools           HTML editors:   PHP + MySQL:          Frameworks:
                Frontpage       Joomla                CakePHP (PHP)
                Dreamweaver     Drupal                Grails (Groovy)
                                Wordpress             Django (Phyton)
                                Typo3                 Ruby on Rails (Ruby)
                                                      Merb (Ruby)
                                .Net                  Sanatra (Ruby)
                                Sharepoint
What is             ?
                                         Creator of Ruby on Rails
• Web application framework            David Heinemeier Hansson

• Open Source (MIT license)
• Based on a existing
  application (Basecamp)
• Provides common needs:
      Routing, sessions
  –
      Database storage
  –
      Business logic
  –
      Generate HTML/XML/CSS/Ajax
  –
      Testing
  –
Who uses Rails
    Internally:
•
    Externally:
•
    style.mtv.com
•
    www.getsatisfaction.com
•
    www.basecamp.com
•
    www.yellowpages.com
•
    www.twitter.com
•
    www.yelloyello.nl
•
Rails Advantages
    Convention over configuration
•
    Don’t Repeat Yourself
•
    Object Relational Mapping
•
    Model View Controller
•                                   Tay Rail Bridge, Scotland
                                                   Ross2085

    Reuse of code
•
    Agile practices
•
    Security
•
Convention over Configuration
• Table and foreign key naming
  – Tables are multiples
    (users, orders, etc.)
  – Foreign key naming: user_id
• Default locations
  – MVC, Tests, Languages, Plugins
• Naming
  – Class names: CamelCase
  – Files: lowercase_underscored.rb
Don’t repeat yourself
• Everything is defined in a single,
  unambiguous place
• Easier to find code
  – Only need to look once
  – Can stop looking when found
  – Well defined places for most items
• Much easier to maintain code
  – Faster to change
  – Less inconsistency bugs
Model View Controller
• Model
  – Object relationships
    (users, orders)
• Controller
  – Business logic
    (perform a payment)
• View
  – Visual representation
    (generate HTML/XML)
Model
• Contains validation and object methods
• Use 'fat' models and 'skinny' controllers to
  increase reuse of methods across controllers
        class Order < ActiveRecord::Base
           has_many :line_items
           has_one :user
           has_one :email, :through => :user

              validates_presence_of :user
              validates_numericality_of :amount

              def purchase
                  self.purchase_time = Now
              end
        end
View
• DSL languages              #content
                               .left.column
      Erb for ruby & html
  •                              %h2 Welcome to our site!
                                 %p= print_information
      Haml improves on erb
  •                            .right.column= render quot;sidebarquot;
      Textile for html
  •
      Sass for css
  •
                       <div id='content'>
                         <div class='left column'>
                           <h2>Welcome to our site!</h2>
                           <p>
                             <%= print_information %>
                           </p>
                         </div>
                         <div class=quot;right columnquot;>
                           <%= render quot;sidebarquot; %>
                         </div>
                       </div>
Controller
                         Method      Resource     Verb
• RESTful                index       /people      GET
                         show        /people/12   GET
  – Better than SOAP     create      /people      POST
  – Easy to understand   update      /people/12   PUT
                         delete      /people/12   DELETE
  – Easy to debug
                         GET /people/12.xml
  – Easy to cache
                         def show
  – Easy to prioritize      @person =
                                Person.find(params[:id])
  – No bottleneck           respond_to do |wants|
  – HTML/XML/JSON                wants.html
                                 wants.xml { render :xml
                         => @person.to_xml }
                            end
                         end
Object Relational Mapping
                                     find
Programming object                               Database row

                                 ORM Tools:
#<User id: 1, login: quot;Sytsequot;,    -ActiveRecord
email: quot;sytse@comcoaster.comquot;,
                                 -DataMapper
description: quot;<p>Sytse studied
                                 -iBATIS
Management Science at the
Universi...quot;, avatar_id: 1,
crypted_password:
quot;b6675cab85b541a91e6d0
                                      save

            # Examples of finding records
            User.find(:all)
            User.find(23).articles
            User.find_by_first_name('Johnny')
            User.order.find(:last).lines_items.count
Re-use of code
• Gems and plugins, more then 1300
  – For authentication, pagination, testing, etc.
• Git allows easy forking and merging
• Github website allows you to give back
• Acts as a portfolio
Agile practices
• Iterations (branch often, merge often)
• Test all the time (TDD, BDD)
  Stories > Tests > Code > Continuous Integration
     Story example
     Feature: Log-in
       In order to view my profile
       As a Registered member
       I want to be required to log-in

     Test example
     Given /I am the registered member quot;quirequot;/ do
       @user = User.new({ :login => 'quire})
       @user.save!
     end
Security
• Rails prevents SQL injection attacks
  – Attacher post in form: quot;some_title; DROP TABLE articles;quot;
  – In bad code this can be injected:
    quot;SELECT * FROM ARTICLES WHERE TITLE = $TITLEquot;
  – Rails will be escape the input automatically:
    @articles = Article.find(:all,
                    :conditions => [:title => params[:title]])
• Rails prevents Cross Site Scripting (XSS)
  – With html_escape in view: <%=h comment.body %>
Rails Disadvantages
• Rails is inefficient
• Rails is hard to deploy




                            Montparnesse 1895
                                  Jeff Mc Neill
Rails is inefficient
   • Rails uses a lot of memory,
     up to 150MB per instance
   • Requires more application servers
   • Where are your development constrains?
Resource           Example application            Rails
Man hours          2.200 hours / e22.000          1.000 hours / e10.000

Project duration   15 weeks of changes / e3.000   10 weeks / e2.000
Computing power    2 servers / e2.000             5 servers / e5.000
Total              e27.000                        e17.000
Rails is hard to deploy
• Harder than PHP, better with Passenger
• Lots of moving parts
  – Rails, apps, gems, plugins
  – Application server, webserver
• Deployment via scripts
  – Via the Capistrano tool
  – Easy to break something
• Deployment to multiple servers
When to use Ruby on Rails?
    New code base and DB            Existing code and DB
•                               •
    High development speed          Low development speed
•                               •
    Complex applications            Simple applications
•                               •
    Web deployment                  Client deployment
•                               •
    Iterative projects              Waterfall projects
•                               •
    Development is expensive        Deployment is expensive
•                               •
    Fixed price project             Hourly rate project
•                               •
    Early adopter client/team       Late majority client/team
•                               •
Re-usable best practices
• Don't Repeat Yourself
• 'Fat' model, 'skinny' controller
• MVC framework
   – CakePHP
• Integration testing
   – Selenium
• DSL's
   – Textile for markup
• Source code repository
   – GIT
• Project management                 Recycle shirt by Brian Damage
   – Github, Lighthouse, Basecamp
Questions?




http://www.dosire.com/

More Related Content

What's hot

Entity provider selection confusion attacks in JAX-RS applications
Entity provider selection confusion attacks in JAX-RS applicationsEntity provider selection confusion attacks in JAX-RS applications
Entity provider selection confusion attacks in JAX-RS applications
Mikhail Egorov
 
The Hacker's Guide to NoSQL Injection
The Hacker's Guide to NoSQL InjectionThe Hacker's Guide to NoSQL Injection
The Hacker's Guide to NoSQL Injection
Patrycja Wegrzynowicz
 
Let's Learn Ruby - Basic
Let's Learn Ruby - BasicLet's Learn Ruby - Basic
Let's Learn Ruby - BasicEddie Kao
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on Rails
mithunsasidharan
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
Sandeep Rawat
 
Javascript Prototype Visualized
Javascript Prototype VisualizedJavascript Prototype Visualized
Javascript Prototype Visualized
军 沈
 
Java programming course for beginners
Java programming course for beginnersJava programming course for beginners
Java programming course for beginners
Eduonix Learning Solutions
 
Developing MIPS Exploits to Hack Routers
Developing MIPS Exploits to Hack RoutersDeveloping MIPS Exploits to Hack Routers
Developing MIPS Exploits to Hack Routers
BGA Cyber Security
 
RESTful API Testing using Postman, Newman, and Jenkins
RESTful API Testing using Postman, Newman, and JenkinsRESTful API Testing using Postman, Newman, and Jenkins
RESTful API Testing using Postman, Newman, and Jenkins
QASymphony
 
Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02
Fariz Darari
 
Serving ML easily with FastAPI
Serving ML easily with FastAPIServing ML easily with FastAPI
Serving ML easily with FastAPI
Sebastián Ramírez Montaño
 
Android Pentesting
Android PentestingAndroid Pentesting
Static Code Analysis
Static Code AnalysisStatic Code Analysis
Static Code Analysis
Annyce Davis
 
Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)
Paige Bailey
 
Clean code
Clean codeClean code
Clean code
Arturo Herrero
 
Lambda and Stream Master class - part 1
Lambda and Stream Master class - part 1Lambda and Stream Master class - part 1
Lambda and Stream Master class - part 1
José Paumard
 
Postman.ppt
Postman.pptPostman.ppt
Postman.ppt
ParrotBAD
 
Tdd and bdd
Tdd and bddTdd and bdd
Tdd and bdd
MohamedSubhiBouchi
 
Spring boot
Spring bootSpring boot
Spring boot
sdeeg
 
Javascript under the hood 2
Javascript under the hood 2Javascript under the hood 2
Javascript under the hood 2
Thang Tran Duc
 

What's hot (20)

Entity provider selection confusion attacks in JAX-RS applications
Entity provider selection confusion attacks in JAX-RS applicationsEntity provider selection confusion attacks in JAX-RS applications
Entity provider selection confusion attacks in JAX-RS applications
 
The Hacker's Guide to NoSQL Injection
The Hacker's Guide to NoSQL InjectionThe Hacker's Guide to NoSQL Injection
The Hacker's Guide to NoSQL Injection
 
Let's Learn Ruby - Basic
Let's Learn Ruby - BasicLet's Learn Ruby - Basic
Let's Learn Ruby - Basic
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on Rails
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
 
Javascript Prototype Visualized
Javascript Prototype VisualizedJavascript Prototype Visualized
Javascript Prototype Visualized
 
Java programming course for beginners
Java programming course for beginnersJava programming course for beginners
Java programming course for beginners
 
Developing MIPS Exploits to Hack Routers
Developing MIPS Exploits to Hack RoutersDeveloping MIPS Exploits to Hack Routers
Developing MIPS Exploits to Hack Routers
 
RESTful API Testing using Postman, Newman, and Jenkins
RESTful API Testing using Postman, Newman, and JenkinsRESTful API Testing using Postman, Newman, and Jenkins
RESTful API Testing using Postman, Newman, and Jenkins
 
Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02
 
Serving ML easily with FastAPI
Serving ML easily with FastAPIServing ML easily with FastAPI
Serving ML easily with FastAPI
 
Android Pentesting
Android PentestingAndroid Pentesting
Android Pentesting
 
Static Code Analysis
Static Code AnalysisStatic Code Analysis
Static Code Analysis
 
Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)
 
Clean code
Clean codeClean code
Clean code
 
Lambda and Stream Master class - part 1
Lambda and Stream Master class - part 1Lambda and Stream Master class - part 1
Lambda and Stream Master class - part 1
 
Postman.ppt
Postman.pptPostman.ppt
Postman.ppt
 
Tdd and bdd
Tdd and bddTdd and bdd
Tdd and bdd
 
Spring boot
Spring bootSpring boot
Spring boot
 
Javascript under the hood 2
Javascript under the hood 2Javascript under the hood 2
Javascript under the hood 2
 

Viewers also liked

Ruby on Rails for beginners
Ruby on Rails for beginnersRuby on Rails for beginners
Ruby on Rails for beginners
Vysakh Sreenivasan
 
JBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
JBUG 11 - Django-The Web Framework For Perfectionists With DeadlinesJBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
JBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
Tikal Knowledge
 
Django, What is it, Why is it cool?
Django, What is it, Why is it cool?Django, What is it, Why is it cool?
Django, What is it, Why is it cool?
Tom Brander
 
Programming for the non-programmer
Programming for the non-programmerProgramming for the non-programmer
Programming for the non-programmerStelian Firez
 
PHP vs. Ruby on Rails
PHP vs. Ruby on RailsPHP vs. Ruby on Rails
PHP vs. Ruby on Rails
Chris Castiglione
 
Le Wagon On Demand - Behind the scenes
Le Wagon On Demand - Behind the scenesLe Wagon On Demand - Behind the scenes
Le Wagon On Demand - Behind the scenes
Sébastien Saunier
 
How Le Wagon uses Trello
How Le Wagon uses TrelloHow Le Wagon uses Trello
How Le Wagon uses Trello
Sébastien Saunier
 
Perl Introduction
Perl IntroductionPerl Introduction
Perl Introduction
Marcos Rebelo
 
Git & GitHub for Beginners
Git & GitHub for BeginnersGit & GitHub for Beginners
Git & GitHub for Beginners
Sébastien Saunier
 
Le Wagon - Technical entrepreneurship
Le Wagon - Technical entrepreneurshipLe Wagon - Technical entrepreneurship
Le Wagon - Technical entrepreneurship
Boris Paillard
 
MVC Demystified: Essence of Ruby on Rails
MVC Demystified: Essence of Ruby on RailsMVC Demystified: Essence of Ruby on Rails
MVC Demystified: Essence of Ruby on Rails
codeinmotion
 
Techical Workflow for a Startup
Techical Workflow for a StartupTechical Workflow for a Startup
Techical Workflow for a Startup
Sébastien Saunier
 
Le Wagon - UI components design
Le Wagon - UI components designLe Wagon - UI components design
Le Wagon - UI components design
Boris Paillard
 
Le Wagon - Bootcamp in Ruby on Rails, HTML, CSS and JavaScript
Le Wagon - Bootcamp in Ruby on Rails, HTML, CSS and JavaScriptLe Wagon - Bootcamp in Ruby on Rails, HTML, CSS and JavaScript
Le Wagon - Bootcamp in Ruby on Rails, HTML, CSS and JavaScript
Boris Paillard
 
Le Wagon's Product Design Sprint
Le Wagon's Product Design SprintLe Wagon's Product Design Sprint
Le Wagon's Product Design Sprint
Boris Paillard
 
Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentation
Joost Hietbrink
 
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory CourseRuby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
peter_marklund
 

Viewers also liked (19)

Ruby on Rails for beginners
Ruby on Rails for beginnersRuby on Rails for beginners
Ruby on Rails for beginners
 
JBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
JBUG 11 - Django-The Web Framework For Perfectionists With DeadlinesJBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
JBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
 
Django, What is it, Why is it cool?
Django, What is it, Why is it cool?Django, What is it, Why is it cool?
Django, What is it, Why is it cool?
 
Programming for the non-programmer
Programming for the non-programmerProgramming for the non-programmer
Programming for the non-programmer
 
PHP vs. Ruby on Rails
PHP vs. Ruby on RailsPHP vs. Ruby on Rails
PHP vs. Ruby on Rails
 
Le Wagon On Demand - Behind the scenes
Le Wagon On Demand - Behind the scenesLe Wagon On Demand - Behind the scenes
Le Wagon On Demand - Behind the scenes
 
How Le Wagon uses Trello
How Le Wagon uses TrelloHow Le Wagon uses Trello
How Le Wagon uses Trello
 
Perl Introduction
Perl IntroductionPerl Introduction
Perl Introduction
 
Git & GitHub for Beginners
Git & GitHub for BeginnersGit & GitHub for Beginners
Git & GitHub for Beginners
 
Le Wagon - Technical entrepreneurship
Le Wagon - Technical entrepreneurshipLe Wagon - Technical entrepreneurship
Le Wagon - Technical entrepreneurship
 
MVC Demystified: Essence of Ruby on Rails
MVC Demystified: Essence of Ruby on RailsMVC Demystified: Essence of Ruby on Rails
MVC Demystified: Essence of Ruby on Rails
 
Techical Workflow for a Startup
Techical Workflow for a StartupTechical Workflow for a Startup
Techical Workflow for a Startup
 
Le Wagon - UI components design
Le Wagon - UI components designLe Wagon - UI components design
Le Wagon - UI components design
 
Le Wagon - Bootcamp in Ruby on Rails, HTML, CSS and JavaScript
Le Wagon - Bootcamp in Ruby on Rails, HTML, CSS and JavaScriptLe Wagon - Bootcamp in Ruby on Rails, HTML, CSS and JavaScript
Le Wagon - Bootcamp in Ruby on Rails, HTML, CSS and JavaScript
 
Le Wagon's Product Design Sprint
Le Wagon's Product Design SprintLe Wagon's Product Design Sprint
Le Wagon's Product Design Sprint
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
 
Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentation
 
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory CourseRuby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 

Similar to When To Use Ruby On Rails

Framework Presentation
Framework PresentationFramework Presentation
Framework Presentation
rmalik2
 
Ruby on Rails 3.1: Let's bring the fun back into web programing
Ruby on Rails 3.1: Let's bring the fun back into web programingRuby on Rails 3.1: Let's bring the fun back into web programing
Ruby on Rails 3.1: Let's bring the fun back into web programing
Bozhidar Batsov
 
Ruby on Rails in UbiSunrise
Ruby on Rails in UbiSunriseRuby on Rails in UbiSunrise
Ruby on Rails in UbiSunrise
Wisely chen
 
Streamlining Your Applications with Web Frameworks
Streamlining Your Applications with Web FrameworksStreamlining Your Applications with Web Frameworks
Streamlining Your Applications with Web Frameworks
guestf7bc30
 
Api Design
Api DesignApi Design
Introduction To Ruby On Rails
Introduction To Ruby On RailsIntroduction To Ruby On Rails
Introduction To Ruby On Rails
Steve Keener
 
Happy Coding with Ruby on Rails
Happy Coding with Ruby on RailsHappy Coding with Ruby on Rails
Happy Coding with Ruby on Rails
Ochirkhuyag Lkhagva
 
Killing the Angle Bracket
Killing the Angle BracketKilling the Angle Bracket
Killing the Angle Bracket
jnewmanux
 
Haml And Sass
Haml And SassHaml And Sass
Haml And Sass
wear
 
Intro To Django
Intro To DjangoIntro To Django
Intro To Django
Udi Bauman
 
Web Development: The Next Five Years
Web Development: The Next Five YearsWeb Development: The Next Five Years
Web Development: The Next Five Years
sneeu
 
Beijing Perl Workshop 2008 Hiveminder Secret Sauce
Beijing Perl Workshop 2008 Hiveminder Secret SauceBeijing Perl Workshop 2008 Hiveminder Secret Sauce
Beijing Perl Workshop 2008 Hiveminder Secret SauceJesse Vincent
 
Hacking with ruby2ruby
Hacking with ruby2rubyHacking with ruby2ruby
Hacking with ruby2ruby
Marc Chung
 
Object Relational Mapping in PHP
Object Relational Mapping in PHPObject Relational Mapping in PHP
Object Relational Mapping in PHP
Rob Knight
 
RubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - KeynoteRubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - Keynote
Dr Nic Williams
 
Optimizing AngularJS Application
Optimizing AngularJS ApplicationOptimizing AngularJS Application
Optimizing AngularJS Application
Md. Ziaul Haq
 
Road to Rails
Road to RailsRoad to Rails
Road to Rails
paoloperrotta
 
Adventurous Merb
Adventurous MerbAdventurous Merb
Adventurous Merb
Matt Todd
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web Apps
Mike Subelsky
 

Similar to When To Use Ruby On Rails (20)

Framework Presentation
Framework PresentationFramework Presentation
Framework Presentation
 
Ruby on Rails 3.1: Let's bring the fun back into web programing
Ruby on Rails 3.1: Let's bring the fun back into web programingRuby on Rails 3.1: Let's bring the fun back into web programing
Ruby on Rails 3.1: Let's bring the fun back into web programing
 
Practical Groovy DSL
Practical Groovy DSLPractical Groovy DSL
Practical Groovy DSL
 
Ruby on Rails in UbiSunrise
Ruby on Rails in UbiSunriseRuby on Rails in UbiSunrise
Ruby on Rails in UbiSunrise
 
Streamlining Your Applications with Web Frameworks
Streamlining Your Applications with Web FrameworksStreamlining Your Applications with Web Frameworks
Streamlining Your Applications with Web Frameworks
 
Api Design
Api DesignApi Design
Api Design
 
Introduction To Ruby On Rails
Introduction To Ruby On RailsIntroduction To Ruby On Rails
Introduction To Ruby On Rails
 
Happy Coding with Ruby on Rails
Happy Coding with Ruby on RailsHappy Coding with Ruby on Rails
Happy Coding with Ruby on Rails
 
Killing the Angle Bracket
Killing the Angle BracketKilling the Angle Bracket
Killing the Angle Bracket
 
Haml And Sass
Haml And SassHaml And Sass
Haml And Sass
 
Intro To Django
Intro To DjangoIntro To Django
Intro To Django
 
Web Development: The Next Five Years
Web Development: The Next Five YearsWeb Development: The Next Five Years
Web Development: The Next Five Years
 
Beijing Perl Workshop 2008 Hiveminder Secret Sauce
Beijing Perl Workshop 2008 Hiveminder Secret SauceBeijing Perl Workshop 2008 Hiveminder Secret Sauce
Beijing Perl Workshop 2008 Hiveminder Secret Sauce
 
Hacking with ruby2ruby
Hacking with ruby2rubyHacking with ruby2ruby
Hacking with ruby2ruby
 
Object Relational Mapping in PHP
Object Relational Mapping in PHPObject Relational Mapping in PHP
Object Relational Mapping in PHP
 
RubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - KeynoteRubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - Keynote
 
Optimizing AngularJS Application
Optimizing AngularJS ApplicationOptimizing AngularJS Application
Optimizing AngularJS Application
 
Road to Rails
Road to RailsRoad to Rails
Road to Rails
 
Adventurous Merb
Adventurous MerbAdventurous Merb
Adventurous Merb
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web Apps
 

Recently uploaded

UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 

Recently uploaded (20)

UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 

When To Use Ruby On Rails

  • 1. When to use Ruby on Rails? Sytse Sijbrandij sytse@dosire.com
  • 2. Contents • Ruby – What is it? – Advantages – Disadvantages • Rails – What is it? – Advantages – Disadvantages • When to use it • Reusable best practices Ruby Beach, Washington, U.S. Kevin Mc Neal
  • 3. What is Ruby? • A scripting language more powerful than Perl and more object-oriented than Python. • Invented in 1993 with inspiration from Perl, Phyton, Smalltalk, Eiffel, Ada, and Lisp. • Designed for programmer productivity and joy instead of machine efficiency. • Follows the principle of least surprise, the language should minimize confusion. Yukihiro 'Matz' Matsumoto • It's easy to work with and to love Ruby. Ruby's Architect
  • 4. Ruby Advantages Elegant • Powerful • Readable • Concise • Ruby and Diamond ring R. M. Rayner
  • 5. describe Bowling do before(:each) do Ruby is @bowling = Bowling.new end Elegant it quot;should score 0 for gutter gamequot; do 20.times { @bowling.hit(0) } @bowling.score.should == 0 end end class NewBowlingGame extends PHPSpec_Context { private $_bowling = null; public function before() { $this->_bowling = new Bowling; } public function itShouldScore0ForGutterGame() { for ($i=1; $i<=20; $i++) { $this->_bowling->hit(0); } $this->spec($this->_bowling->score)->should->equal(0); } }
  • 6. Ruby is Powerful • Object-oriented (everything is an object) • Dynamic (duck typing) # Open Ruby's Time class and add a method class Time def yesterday self - 86400 end end today = Time.now # => Thu Aug 14 16:51:50 +1200 2008 yesterday = today.yesterday # => Wed Aug 13 16:51:50 +1200 2008
  • 7. Ruby is Readable • The code comments itself • Leads to better naming practices # An example example function for a photo camera program def shutter_clicked capture_image if @camera.on? and @camera.memory_available? end
  • 8. Ruby is Concise • Very expressive language • Less lines of code, higher productivity -199.abs # 199 quot;ruby is coolquot;.length # 12 quot;Your Momquot;.index(quot;uquot;) #2 quot;Nice Day!quot;.downcase.split(//).sort.uniq.join # quot; !acdeinyquot; say = quot;I love Rubyquot; say['love'] = quot;*love*quot; 5.times { puts say } => quot;I *love* Rubyquot; quot;I *love* Rubyquot; quot;I *love* Rubyquot; quot;I *love* Rubyquot; quot;I *love* Rubyquot;
  • 9. Ruby Disadvantages • Ruby is Slow • Ruby is New Ruby Fails Falls, Lookout Mountain, U.S. Oscar & L
  • 10. Ruby is Slow • About 10x slower than Java, 2x slower than PHP All benchmarks, x64 Ubuntu, Intel Q6600 Quad Computer Language Benchmarks Game
  • 11. Ruby is New • Not many developers or customers • No common IDE – Most coders use the Mac text-editor Textmate – IDEs: RadRails, RubyMine, 3rd Rail, Netbeans • No common application server – Passenger's Apache module has momentum
  • 12. Evolution to web frameworks From 1990 to 2009 Time Static Dynamic Integrated Type of site Marketing Front office Back office Business role • Brochure • Communication • Quotations • Advertising • Ordering • Fulfillment • Mailings • Legacy systems Tools HTML editors: PHP + MySQL: Frameworks: Frontpage Joomla CakePHP (PHP) Dreamweaver Drupal Grails (Groovy) Wordpress Django (Phyton) Typo3 Ruby on Rails (Ruby) Merb (Ruby) .Net Sanatra (Ruby) Sharepoint
  • 13. What is ? Creator of Ruby on Rails • Web application framework David Heinemeier Hansson • Open Source (MIT license) • Based on a existing application (Basecamp) • Provides common needs: Routing, sessions – Database storage – Business logic – Generate HTML/XML/CSS/Ajax – Testing –
  • 14. Who uses Rails Internally: • Externally: • style.mtv.com • www.getsatisfaction.com • www.basecamp.com • www.yellowpages.com • www.twitter.com • www.yelloyello.nl •
  • 15. Rails Advantages Convention over configuration • Don’t Repeat Yourself • Object Relational Mapping • Model View Controller • Tay Rail Bridge, Scotland Ross2085 Reuse of code • Agile practices • Security •
  • 16. Convention over Configuration • Table and foreign key naming – Tables are multiples (users, orders, etc.) – Foreign key naming: user_id • Default locations – MVC, Tests, Languages, Plugins • Naming – Class names: CamelCase – Files: lowercase_underscored.rb
  • 17. Don’t repeat yourself • Everything is defined in a single, unambiguous place • Easier to find code – Only need to look once – Can stop looking when found – Well defined places for most items • Much easier to maintain code – Faster to change – Less inconsistency bugs
  • 18. Model View Controller • Model – Object relationships (users, orders) • Controller – Business logic (perform a payment) • View – Visual representation (generate HTML/XML)
  • 19. Model • Contains validation and object methods • Use 'fat' models and 'skinny' controllers to increase reuse of methods across controllers class Order < ActiveRecord::Base has_many :line_items has_one :user has_one :email, :through => :user validates_presence_of :user validates_numericality_of :amount def purchase self.purchase_time = Now end end
  • 20. View • DSL languages #content .left.column Erb for ruby & html • %h2 Welcome to our site! %p= print_information Haml improves on erb • .right.column= render quot;sidebarquot; Textile for html • Sass for css • <div id='content'> <div class='left column'> <h2>Welcome to our site!</h2> <p> <%= print_information %> </p> </div> <div class=quot;right columnquot;> <%= render quot;sidebarquot; %> </div> </div>
  • 21. Controller Method Resource Verb • RESTful index /people GET show /people/12 GET – Better than SOAP create /people POST – Easy to understand update /people/12 PUT delete /people/12 DELETE – Easy to debug GET /people/12.xml – Easy to cache def show – Easy to prioritize @person = Person.find(params[:id]) – No bottleneck respond_to do |wants| – HTML/XML/JSON wants.html wants.xml { render :xml => @person.to_xml } end end
  • 22. Object Relational Mapping find Programming object Database row ORM Tools: #<User id: 1, login: quot;Sytsequot;, -ActiveRecord email: quot;sytse@comcoaster.comquot;, -DataMapper description: quot;<p>Sytse studied -iBATIS Management Science at the Universi...quot;, avatar_id: 1, crypted_password: quot;b6675cab85b541a91e6d0 save # Examples of finding records User.find(:all) User.find(23).articles User.find_by_first_name('Johnny') User.order.find(:last).lines_items.count
  • 23. Re-use of code • Gems and plugins, more then 1300 – For authentication, pagination, testing, etc. • Git allows easy forking and merging • Github website allows you to give back • Acts as a portfolio
  • 24. Agile practices • Iterations (branch often, merge often) • Test all the time (TDD, BDD) Stories > Tests > Code > Continuous Integration Story example Feature: Log-in In order to view my profile As a Registered member I want to be required to log-in Test example Given /I am the registered member quot;quirequot;/ do @user = User.new({ :login => 'quire}) @user.save! end
  • 25. Security • Rails prevents SQL injection attacks – Attacher post in form: quot;some_title; DROP TABLE articles;quot; – In bad code this can be injected: quot;SELECT * FROM ARTICLES WHERE TITLE = $TITLEquot; – Rails will be escape the input automatically: @articles = Article.find(:all, :conditions => [:title => params[:title]]) • Rails prevents Cross Site Scripting (XSS) – With html_escape in view: <%=h comment.body %>
  • 26. Rails Disadvantages • Rails is inefficient • Rails is hard to deploy Montparnesse 1895 Jeff Mc Neill
  • 27. Rails is inefficient • Rails uses a lot of memory, up to 150MB per instance • Requires more application servers • Where are your development constrains? Resource Example application Rails Man hours 2.200 hours / e22.000 1.000 hours / e10.000 Project duration 15 weeks of changes / e3.000 10 weeks / e2.000 Computing power 2 servers / e2.000 5 servers / e5.000 Total e27.000 e17.000
  • 28. Rails is hard to deploy • Harder than PHP, better with Passenger • Lots of moving parts – Rails, apps, gems, plugins – Application server, webserver • Deployment via scripts – Via the Capistrano tool – Easy to break something • Deployment to multiple servers
  • 29. When to use Ruby on Rails? New code base and DB Existing code and DB • • High development speed Low development speed • • Complex applications Simple applications • • Web deployment Client deployment • • Iterative projects Waterfall projects • • Development is expensive Deployment is expensive • • Fixed price project Hourly rate project • • Early adopter client/team Late majority client/team • •
  • 30. Re-usable best practices • Don't Repeat Yourself • 'Fat' model, 'skinny' controller • MVC framework – CakePHP • Integration testing – Selenium • DSL's – Textile for markup • Source code repository – GIT • Project management Recycle shirt by Brian Damage – Github, Lighthouse, Basecamp