SlideShare a Scribd company logo
1 of 31
Download to read offline
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

What's hot (20)

Celery: The Distributed Task Queue
Celery: The Distributed Task QueueCelery: The Distributed Task Queue
Celery: The Distributed Task Queue
 
Web Development with Laravel 5
Web Development with Laravel 5Web Development with Laravel 5
Web Development with Laravel 5
 
Spring GraphQL
Spring GraphQLSpring GraphQL
Spring GraphQL
 
Clean architecture with ddd layering in php
Clean architecture with ddd layering in phpClean architecture with ddd layering in php
Clean architecture with ddd layering in php
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
 
Asynchronous JavaScript Programming
Asynchronous JavaScript ProgrammingAsynchronous JavaScript Programming
Asynchronous JavaScript Programming
 
Modern JavaScript Frameworks: Angular, React & Vue.js
Modern JavaScript Frameworks: Angular, React & Vue.jsModern JavaScript Frameworks: Angular, React & Vue.js
Modern JavaScript Frameworks: Angular, React & Vue.js
 
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 JavaScript - Chapter 9 - TypeConversion and Regular Expressions  JavaScript - Chapter 9 - TypeConversion and Regular Expressions
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 
MMUG18 - MySQL Failover and Orchestrator
MMUG18 - MySQL Failover and OrchestratorMMUG18 - MySQL Failover and Orchestrator
MMUG18 - MySQL Failover and Orchestrator
 
How to set up orchestrator to manage thousands of MySQL servers
How to set up orchestrator to manage thousands of MySQL serversHow to set up orchestrator to manage thousands of MySQL servers
How to set up orchestrator to manage thousands of MySQL servers
 
Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition!
Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition! Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition!
Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition!
 
REST API Design & Development
REST API Design & DevelopmentREST API Design & Development
REST API Design & Development
 
Postman Collection Format v2.0 (pre-draft)
Postman Collection Format v2.0 (pre-draft)Postman Collection Format v2.0 (pre-draft)
Postman Collection Format v2.0 (pre-draft)
 
Introduction to the Web API
Introduction to the Web APIIntroduction to the Web API
Introduction to the Web API
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JS
 
Learn REST in 18 Slides
Learn REST in 18 SlidesLearn REST in 18 Slides
Learn REST in 18 Slides
 
Présentation jQuery pour débutant
Présentation jQuery pour débutantPrésentation jQuery pour débutant
Présentation jQuery pour débutant
 
Ruby On Rails Basics
Ruby On Rails BasicsRuby On Rails Basics
Ruby On Rails Basics
 
GraalVm and Quarkus
GraalVm and QuarkusGraalVm and Quarkus
GraalVm and Quarkus
 
Ruby Basics
Ruby BasicsRuby Basics
Ruby Basics
 

Viewers also liked

Programming for the non-programmer
Programming for the non-programmerProgramming for the non-programmer
Programming for the non-programmer
Stelian Firez
 

Viewers also liked (20)

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
RubyRuby
Ruby
 
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

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
Jesse Vincent
 

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

Recently uploaded (20)

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

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