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 Ruby Conf Malaysia

Michael Cheng

October 13, 2017
Tweet

More Decks by Michael Cheng

Other Decks in Programming

Transcript

  1. Michael Cheng
    @coderkungfu

    @engineersftw

    View full-size slide

  2. Senior Software Engineer, Singapore Power’s Digital Technologies Team

    View full-size slide

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

    View full-size slide

  4. Singapore PHP User Group (started in 2007)

    View full-size slide

  5. 5
    Rasmus Lerdorf, Creator of PHP

    View full-size slide

  6. 6
    PHPConf.Asia 2015

    View full-size slide

  7. 7
    Joined Neo Innovation in 2014

    View full-size slide

  8. 8
    TechLadies Bootcamp (2017) - Mountbatten Vocational School

    View full-size slide

  9. 9
    Yukihiro Matsumoto, Creator of Ruby

    View full-size slide

  10. MVC Web Frameworks in PHP
    10

    View full-size slide

  11. Ruby vs PHP?
    11

    View full-size slide

  12. Similarities
    • Interpreted languages
    • Dynamically typed
    • Easy to understand syntax
    • Object Oriented
    12

    View full-size slide

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

    View full-size slide

  14. Syntax Compared
    14
    “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
    SOME_CONSTANT
    Klass::SOME_CONST

    View full-size slide

  15. Syntax Compared
    15
    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 full-size slide

  16. Syntax Compared
    16
    if($morning == true){
    echo “Hullo”
    }
    if ($morning)
    echo “Hullo”
    if morning?
    puts “Hullo”
    end
    puts “Hullo” if
    morning?

    View full-size slide

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

    View full-size slide

  18. Where Ruby Wins!
    • No semi-colons needed at end of statements
    • Dot is not used for concatenation
    • Calling methods on objects with 1 less character
    • @user.name and not $user->name
    • Curly braces are not necessary
    • What opening tags? 18

    View full-size slide

  19. What I like about Ruby?
    • Tooling support
    • Testing, profiling and debugging are not an after-thought
    • Dependency management is easy
    • Easily switch between Ruby versions
    • Open source community / ecosystem
    • Problems solved by smart people
    19

    View full-size slide

  20. Ruby on Rails
    20

    View full-size slide

  21. What I like about Rails?
    • No need to depend on separate web server for
    development (build-in web server)
    • Command Line Interface (CLI) support and tools
    • rails new
    • Track DB schema changes (relatively) easily
    • "There's a Gem for that”™
    21

    View full-size slide

  22. What I like about Rails?
    • MVP friendly
    • 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
    • Many deployment options
    • PaaS - Heroku, Azure
    • Self host via VPS, shared hosting
    22

    View full-size slide

  23. 23
    More Ruby than PHP repositories

    View full-size slide

  24. 24
    Engineers.SG

    View full-size slide

  25. 25
    Upload site for Engineers.SG - Rails, Nginx, Passenger, Sidekiq

    View full-size slide

  26. 26
    Bootcamp 2017

    View full-size slide

  27. Downside
    • BYO web server (for static content)
    • Quite memory intensive
    • Mostly solvable by throwing machines at the problem.
    (i.e. more money)
    27

    View full-size slide

  28. Reflections
    • These are merely tools for building great web apps
    • Figure out the best tool for the job
    • Test, Build, Validate, Iterate
    • Knowledge in design patterns is important in
    understanding how we build apps better
    • Can still write 7000 line spaghetti Ruby files
    28

    View full-size slide

  29. Where to start?
    • TryRuby - http://tryruby.org
    • RailsGirls Guide - http://guides.railsgirls.com
    • Ruby On Rails Tutorial - https://www.railstutorial.org
    • RailsCast - http://railscasts.com (outdated, but good
    starting point)
    • Ruby Meetup - https://www.meetup.com/ruby-malaysia/
    29

    View full-size slide

  30. Michael Cheng
    @coderkungfu

    @engineersftw

    View full-size slide