SlideShare una empresa de Scribd logo
1 de 31
Descargar para leer sin conexión
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/

Más contenido relacionado

La actualidad más candente

Asynchronous JavaScript Programming
Asynchronous JavaScript ProgrammingAsynchronous JavaScript Programming
Asynchronous JavaScript ProgrammingHaim Michael
 
Let's Learn Ruby - Basic
Let's Learn Ruby - BasicLet's Learn Ruby - Basic
Let's Learn Ruby - BasicEddie Kao
 
JavaScript: Variables and Functions
JavaScript: Variables and FunctionsJavaScript: Variables and Functions
JavaScript: Variables and FunctionsJussi Pohjolainen
 
AngularJS for Beginners
AngularJS for BeginnersAngularJS for Beginners
AngularJS for BeginnersEdureka!
 
TypeScript Best Practices
TypeScript Best PracticesTypeScript Best Practices
TypeScript Best Practicesfelixbillon
 
Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.David Gómez García
 
ES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern JavascriptES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern JavascriptWojciech Dzikowski
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript TutorialBui Kiet
 
Intro to Asynchronous Javascript
Intro to Asynchronous JavascriptIntro to Asynchronous Javascript
Intro to Asynchronous JavascriptGarrett Welson
 
Ruby Basics
Ruby BasicsRuby Basics
Ruby BasicsSHC
 
Golang (Go Programming Language)
Golang (Go Programming Language)Golang (Go Programming Language)
Golang (Go Programming Language)ShubhamMishra485
 
ASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewShahed Chowdhuri
 

La actualidad más candente (20)

Clean Code
Clean CodeClean Code
Clean Code
 
Asynchronous JavaScript Programming
Asynchronous JavaScript ProgrammingAsynchronous JavaScript Programming
Asynchronous JavaScript Programming
 
Let's Learn Ruby - Basic
Let's Learn Ruby - BasicLet's Learn Ruby - Basic
Let's Learn Ruby - Basic
 
JavaScript: Variables and Functions
JavaScript: Variables and FunctionsJavaScript: Variables and Functions
JavaScript: Variables and Functions
 
AngularJS for Beginners
AngularJS for BeginnersAngularJS for Beginners
AngularJS for Beginners
 
TypeScript Best Practices
TypeScript Best PracticesTypeScript Best Practices
TypeScript Best Practices
 
Angularjs PPT
Angularjs PPTAngularjs PPT
Angularjs PPT
 
TypeScript Presentation
TypeScript PresentationTypeScript Presentation
TypeScript Presentation
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
 
Java Script ppt
Java Script pptJava Script ppt
Java Script ppt
 
TypeScript Overview
TypeScript OverviewTypeScript Overview
TypeScript Overview
 
Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.
 
ES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern JavascriptES2015 / ES6: Basics of modern Javascript
ES2015 / ES6: Basics of modern Javascript
 
Ruby programming
Ruby programmingRuby programming
Ruby programming
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
 
Intro to Asynchronous Javascript
Intro to Asynchronous JavascriptIntro to Asynchronous Javascript
Intro to Asynchronous Javascript
 
Ruby Basics
Ruby BasicsRuby Basics
Ruby Basics
 
Golang (Go Programming Language)
Golang (Go Programming Language)Golang (Go Programming Language)
Golang (Go Programming Language)
 
ASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with OverviewASP.NET Core MVC + Web API with Overview
ASP.NET Core MVC + Web API with Overview
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
 

Destacado

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 DeadlinesTikal 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
 
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 scenesSébastien Saunier
 
Le Wagon - Technical entrepreneurship
Le Wagon - Technical entrepreneurshipLe Wagon - Technical entrepreneurship
Le Wagon - Technical entrepreneurshipBoris 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 Railscodeinmotion
 
Techical Workflow for a Startup
Techical Workflow for a StartupTechical Workflow for a Startup
Techical Workflow for a StartupSébastien Saunier
 
Le Wagon - UI components design
Le Wagon - UI components designLe Wagon - UI components design
Le Wagon - UI components designBoris 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 JavaScriptBoris Paillard
 
Le Wagon's Product Design Sprint
Le Wagon's Product Design SprintLe Wagon's Product Design Sprint
Le Wagon's Product Design SprintBoris Paillard
 
Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails PresentationJoost 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 Coursepeter_marklund
 

Destacado (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 a When To Use Ruby On Rails

Framework Presentation
Framework PresentationFramework Presentation
Framework Presentationrmalik2
 
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 programingBozhidar Batsov
 
Ruby on Rails in UbiSunrise
Ruby on Rails in UbiSunriseRuby on Rails in UbiSunrise
Ruby on Rails in UbiSunriseWisely chen
 
Streamlining Your Applications with Web Frameworks
Streamlining Your Applications with Web FrameworksStreamlining Your Applications with Web Frameworks
Streamlining Your Applications with Web Frameworksguestf7bc30
 
Introduction To Ruby On Rails
Introduction To Ruby On RailsIntroduction To Ruby On Rails
Introduction To Ruby On RailsSteve Keener
 
Killing the Angle Bracket
Killing the Angle BracketKilling the Angle Bracket
Killing the Angle Bracketjnewmanux
 
Haml And Sass
Haml And SassHaml And Sass
Haml And Sasswear
 
Intro To Django
Intro To DjangoIntro To Django
Intro To DjangoUdi Bauman
 
Web Development: The Next Five Years
Web Development: The Next Five YearsWeb Development: The Next Five Years
Web Development: The Next Five Yearssneeu
 
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 ruby2rubyMarc Chung
 
Object Relational Mapping in PHP
Object Relational Mapping in PHPObject Relational Mapping in PHP
Object Relational Mapping in PHPRob Knight
 
RubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - KeynoteRubyEnRails2007 - Dr Nic Williams - Keynote
RubyEnRails2007 - Dr Nic Williams - KeynoteDr Nic Williams
 
Optimizing AngularJS Application
Optimizing AngularJS ApplicationOptimizing AngularJS Application
Optimizing AngularJS ApplicationMd. Ziaul Haq
 
Adventurous Merb
Adventurous MerbAdventurous Merb
Adventurous MerbMatt 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 AppsMike Subelsky
 

Similar a 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
 

Último

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
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.pdfUK Journal
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
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)wesley chun
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
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?Igalia
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
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 RobisonAnna Loughnan Colquhoun
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 

Último (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
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
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
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)
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
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?
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

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