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. 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
  2. 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
  3. 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
  4. 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
  5. Differences • PHP • Web centric • Not quite a

    language - collection of functions • Ruby • General purpose (more effort to make web) • An expressive programming language 11
  6. 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
  7. 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” }
  8. Specifics… 14 if($morning == true){ echo “Hullo” } if ($morning)

    echo “Hullo” if morning? puts “Hullo” end puts “Hullo” if morning?
  9. 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
  10. Other similarities… • Console (irb / php interative shell) •

    Debugging (pry / phpdbg) • Testing (TestUnit, Rspec / PHPUnit) 16
  11. Other similarities… • Healthy open source ecosystem • http://rubygems.org/ &

    https:// www.ruby-toolbox.com/ • http://packagist.org • Dependency management / packaging • Bundler / Composer 17
  12. 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
  13. What I like about Ruby? • Testing • Unit testing

    • Feature testing • Mocking / Stubbing 19
  14. 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
  15. What about Rails? • Running tasks are easy • Emailers

    are easy • Track DB schema changes easily • Command line interface 22
  16. 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
  17. 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
  18. 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
  19. RoR: We invented Automagic • Example: • Devise - Login,

    registration, password reset, emails, timeout, etc. • CarrierWave - File upload, S3 support, custom URL, thumbnails, etc. 26
  20. 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
  21. 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
  22. Downside • Quite memory intensive • Mostly solvable by throwing

    machines at the problem. :p (i.e. more money) 29
  23. Where to start? • TryRuby • http://tryruby.org • RailsCast •

    http://railscasts.com/ • Ruby Meetup • http://www.meetup.com/Singapore- Ruby-Group/ 30
  24. 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