Upgrade to Pro — share decks privately, control downloads, hide ads and more …

What about Ruby on Rails? ... from a PHP guy

What about Ruby on Rails? ... from a PHP guy

Presented at GeekCampSG 2014

Michael Cheng

October 17, 2014
Tweet

More Decks by Michael Cheng

Other Decks in Programming

Transcript

  1. …from a PHP guy
    What About Ruby on Rails?
    1

    View Slide

  2. Michael Cheng
    Software Engineer, Neo Innovation Inc.
    http://twitter.com/coderkungfu
    http://github.com/miccheng
    http://CoderKungfu.com
    2

    View Slide

  3. Speaker Deck
    3
    http://bit.ly/rorfromphp

    View Slide

  4. About Me
    • Self-learned front-end / back-end / iOS developer
    • Building web apps since 2001
    • Started Singapore PHP User Group in 2006
    • Co-founded iOS Dev Scout (2012)
    • Worked in startups: Foound (2010) and mig33 (2012)
    • Joined Neo Innovation Inc. in March 2014
    4

    View Slide

  5. Ruby on Rails vs PHP?
    5

    View Slide

  6. Its an unfair comparison…
    • Ruby on Rails in a software framework
    written in Ruby (a programming
    language)
    • PHP is a programming language

    … or so it thinks… :)
    • Should compare Ruby vs PHP?
    • Or Rails vs CakePHP/Symfony/Laravel
    6

    View Slide

  7. Ruby
    • A dynamic, open source programming
    language with a focus on simplicity and
    productivity. It has an elegant syntax that is
    natural to read and easy to write
    • Created by Yukihiro “Matz” Matsumoto
    • Public release in 1995
    • Currently version 2.1.3
    • Ruby on Rails released in 2004
    7

    View Slide

  8. PHP
    • Created in 1994 by Rasmus Lerdorf as a
    collection of CGI scripts written in C
    • In 1997, Andi Gutmans and Zeev Suraski of
    Tel Aviv, Israel started a complete rewrite of
    the parser - first steps to becoming a real
    language
    • Released PHP 3 in 1998 - Changed meaning
    to “PHP: Hypertext Preprocessor”
    • Currently version 5.6.2
    8

    View Slide

  9. Ruby vs PHP?
    9

    View Slide

  10. Similarities
    • Interpreted languages
    • Dynamically typed
    • Easy to understand syntax
    • Object oriented
    10

    View Slide

  11. Differences
    • PHP
    • Web centric
    • Not quite a
    language -
    collection of
    functions
    • Ruby
    • General purpose
    (more effort to
    make web)
    • An expressive
    programming
    language
    11

    View Slide

  12. Specifics…
    12
    “A string” “Hello,
    $name”
    42
    3.146
    $variable
    $obj->variable
    Klass::$static_var
    SOME_CONSTANT
    Klass::SOME_CONST
    “A string” “Hello
    #{name}”
    42
    3.146
    local_variable
    $global_var
    Klass.class_var
    SAME_CONSTANT
    Klass::SOME_CONST

    View Slide

  13. Specifics…
    13
    array(10, 20, 30)
    array(1, 2, 3, 4, 5)
    array(
    “a” => “Apple”,
    “b” => “Banana”
    )
    [10, 20, 30]
    [1..5]
    {
    a: “Apple”,
    b: “Banana”
    }

    View Slide

  14. Specifics…
    14
    if($morning == true){
    echo “Hullo”
    }
    if ($morning)
    echo “Hullo”
    if morning?
    puts “Hullo”
    end
    puts “Hullo” if morning?

    View Slide

  15. Specifics…
    15
    class Tea extends Beverages{
    private $water
    private $milk
    public function __construct(){
    $this->water = true;
    $this->milk = true;
    }
    public function is_good(){
    return true;
    }
    }
    class Tea < Beverages
    def initialize
    @water = true
    @milk = true
    end
    def good?
    true
    end
    private
    def secret
    “hello”
    end
    end

    View Slide

  16. Other similarities…
    • Console (irb / php interative shell)
    • Debugging (pry / phpdbg)
    • Testing (TestUnit, Rspec / PHPUnit)
    16

    View Slide

  17. Other similarities…
    • Healthy open source ecosystem
    • http://rubygems.org/ & https://
    www.ruby-toolbox.com/
    • http://packagist.org
    • Dependency management / packaging
    • Bundler / Composer
    17

    View Slide

  18. What I like about Ruby?
    • Ecosystem
    • Problems solved by smart people
    • Tools for developer happyness
    • Debugging, Testing
    • Packaging, dependency management
    • Deployment
    • Running multiple versions on the same
    machine
    18

    View Slide

  19. What I like about Ruby?
    • Testing
    • Unit testing
    • Feature testing
    • Mocking / Stubbing
    19

    View Slide

  20. Ruby on Rails
    20

    View Slide

  21. What about Rails?
    • Front-end web application framework
    • An opinion on how to build a web app
    • Convention over configuration
    • MVC
    • Big on testing
    • Unit, behaviour, feature
    21

    View Slide

  22. What about Rails?
    • Running tasks are easy
    • Emailers are easy
    • Track DB schema changes easily
    • Command line interface
    22

    View Slide

  23. What about Rails?
    • "There's a Gem for that”TM
    • Problems already solved
    • Usually drop in solutions with minimal
    tweaking (defaults are good enough)
    23

    View Slide

  24. PHP: We invent the wheel
    • We have full control & knowledge of
    how things work
    • Usually because we had to code it
    ourselves by hand
    • Even when you use a framework like
    CakePHP, Laravel, Symfony… you still
    have to write a lot of code
    24

    View Slide

  25. RoR: We invented Automagic
    • It works like magic
    • It works, provides for common use
    cases & standards
    • It's usually relatively secure &
    production ready out of the box
    • Really lends itself to rapid development,
    MVP
    25

    View Slide

  26. RoR: We invented Automagic
    • Example:
    • Devise - Login, registration, password
    reset, emails, timeout, etc.
    • CarrierWave - File upload, S3 support,
    custom URL, thumbnails, etc.
    26

    View Slide

  27. Benefits
    • Faster ramp-up for building your web app
    • Commonly used stuff are already build - just
    add the Gem, configure and go!
    • From idea to product in short time - and its
    relatively secure and beta tester ready
    • Easier deployment options
    • PaaS - Heroku, Azure
    • Self host via VPS, shared hosting
    27

    View Slide

  28. Benefits
    • Continuous Integration/Deployment friendly
    • Easily testable - ensure your product does
    what its supposed to
    • Flexible DB options
    • Easy to Google / StackOverflow for
    solutions
    • CLI FTW!
    28

    View Slide

  29. Downside
    • Quite memory intensive
    • Mostly solvable by throwing machines at
    the problem. :p (i.e. more money)
    29

    View Slide

  30. Where to start?
    • TryRuby
    • http://tryruby.org
    • RailsCast
    • http://railscasts.com/
    • Ruby Meetup
    • http://www.meetup.com/Singapore-
    Ruby-Group/
    30

    View Slide

  31. Where to start?
    • Rails Girls Singapore
    • http://railsgirls.com/singapore
    • http://www.meetup.com/Singapore-Ruby-
    Group/events/213119462/
    • Sat, 25 Oct 2014 @ ThoughtWorks Singapore
    (87B, Amoy Street, #03/04)
    31

    View Slide

  32. http://www.neo.com/jobs#Singapore
    We’re Hiring!
    32

    View Slide