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

Ruby and Rails

Ruby and Rails

Ruby and Rails techbar @ devmarche

Alessandro Lepore

October 13, 2016
Tweet

More Decks by Alessandro Lepore

Other Decks in Programming

Transcript

  1. SELF ➤ Alessandro Lepore ➤ Freelance developer @ freego ➤

    github.com/alepore // github.com/freego //@alelepore ➤ Perl => (Audio) => PHP => Ruby => ? ➤ Longtime Linux User, Open source enthusiast
  2. AGENDA ➤ Pizza ➤ Ruby: the language ➤ Rails: the

    web framework ➤ Live app coding ➤ Deploy ➤ Profit!
  3. RUBY: THE LANGUAGE ➤ Interpreted, Dynamic, Object-oriented, general-purpose programming language

    ➤ Also functional and imperative ➤ Dynamic type system and automatic memory management ➤ Native plug-in API in C ➤ BSD / MIT license ➤ “I hope to see Ruby help every programmer in the world to be productive, and to enjoy programming, and to be happy. That is the primary purpose of Ruby.”
  4. RUBY: HISTORY ➤ Yukihiro Matsumoto (“Matz”), from Japan ➤ 1995,

    Ruby 0.95 ➤ 2001, first English book ➤ 2003, Ruby 1.8 ➤ 2004, RubyGems ➤ 2005, Ruby on Rails ➤ 2011, Ruby 1.9.3 ➤ 2013-2016: Ruby 2.x “Matz is nice and so we are nice”
  5. RUBY: DETAILS ➤ Thoroughly object-oriented with inheritance, mixins and metaclasses

    ➤ Dynamic typing and duck typing ➤ Succinct and flexible syntax that minimises syntactic noise ➤ Dynamic reflection and alteration of objects to facilitate metaprogramming ➤ Lexical closures, iterators and generators, with a unique block syntax ➤ Strict boolean coercion rules (everything is true except false and nil) ➤ Exception handling ➤ Custom dispatch behaviour (through method_missing and const_missing) ➤ Native plug-in API in C ➤ Interactive Ruby Shell (a REPL) ➤ Centralised package management through RubyGems ➤ Implemented on all major platforms ➤ Large standard library, many gems
  6. RUBY: IMPLEMENTATIONS ➤ CRuby (MRI) ➤ C ➤ JRuby ➤

    Ruby on JVM ➤ Rubinius :( ➤ C++ / Ruby ➤ MRuby - Lightweight and easily embeddable Ruby ➤ Opal - Ruby to JS source-to-source compiler ➤ Ruby Motion - iOS, OS X and Android
  7. (C)RUBY: THE BAD PARTS ➤ Performance ➤ Difficult to optimise,

    no JIT ➤ Concurrency and Parallelism ➤ Threads, GVL ➤ Dynamic typing (?) ➤ Memory usage ➤ Alternate syntaxes ➤ “The Standard Library is a ghetto” Ruby 3!
 (maybe)
  8. (RUBY ON) RAILS: HISTORY ➤ David Heinemeier Hansson (DHH), Denmark

    ➤ Hired by Jason Fried for 37signals' Basecamp ➤ Used the then-obscure Ruby language to develop a custom web framework ➤ 2005: Open Source Extraction from Basecamp ➤ 2007: Rails included in Mac OS X “Leopard”! ➤ 2009: Rails 2.3 ➤ 2012: Rails 3.2 ➤ 2013: Rails 4.0 ➤ 2014: Rails 4.2 ➤ 2016: Rails 5.0
  9. (RUBY ON) RAILS: THE WEB FRAMEWORK ➤ Full stack Ruby

    web framework ➤ Model, View, Controller pattern ➤ …and other well-known patterns and paradigms ➤ “Anti-enterprise” ➤ “Rails is convincing people that they can do projects with small teams, with simpler goals and simpler results released in smaller iterations”
  10. RAILS: THE DOCTRINE (RUBYONRAILS.ORG/DOCTRINE) 1. Optimize for programmer happiness 2.

    Convention over Configuration 3. The menu is omakase 4. No one paradigm 5. Exalt beautiful code 6. Provide sharp knives 7. Value integrated systems 8. Progress over stability 9. Push up a big tent
  11. RAILS: NOT THE ONLY ONE ➤ Sinatra ➤ Classy web-development

    dressed in a DSL ➤ Hanami ➤ Full-featured, but lightweight ➤ “Bring back Object Oriented Programming to web development” ➤ Volt ➤ Your ruby code runs on both the server and the client ➤ …and lots of “micro frameworks”
  12. RAILS: COMPONENTS ➤ activesupport: Utility classes and Ruby extensions ➤

    actionpack: From request to response ➤ actionview: View template lookup and rendering ➤ activemodel: Model interfaces ➤ activerecord: Object-relational mapping ➤ actioncable: Integrated WebSockets ➤ railties: gluing all frameworks together ➤ sprockets: asset packaging system ➤ actionmailer: Easy email delivery and testing ➤ activejob: Make work happen later
  13. BASIC RAILS ENVIRONMENT ➤ UNIX-like environment (preferred) ➤ Ruby ➤

    Ruby version manager (RVM, Rbenv, chruby) ➤ git ➤ Your favourite editor ➤ Sublime Text ➤ Vim ➤ Atom ➤ TextMate ➤ Emacs ➤ JetBrains RubyMine
  14. SIZR: A SIMPLE RAILS APP ➤ Users ➤ Can insert

    garments ➤ Garment belongs to brand ➤ Garment has many sizes ➤ Can record how a size wear ➤ Can register, log in
  15. RAILS: PRODUCTION DEPLOY ➤ heroku.com ➤ fully automated/managed ➤ Capistrano

    ➤ need a server with: ➤ SSH ➤ ruby ➤ Git/HG/SVN ➤ Nginx ➤ mysql/oracle/postgresql/sqlite3/frontbase/ibm_db/sqlserver ➤ some common libs
  16. THE RUBY LEGACY ➤ Crystal Lang (2014) ➤ Syntax very

    similar to Ruby (compatibility not a goal) ➤ “Fast as C, slick as Ruby”, compile to efficient native code ➤ Statically type-checked ➤ Elixir (2012) ➤ Dynamic, functional, meta-programming aware ➤ Erlang VM, Hot-swappable code for zero-downtime deploys ➤ Low-latency, distributed, highly concurrent, scalable and fault-tolerant systems ➤ Phoenix web framework is awesome
  17. LINKS ➤ ruby-lang.org ➤ rubyonrails.org ➤ guides.rubyonrails.org ➤ rubygems.org ➤

    jruby.org ➤ rubinius.com ➤ opalrb.org ➤ rubymotion.com ➤ mruby.org ➤ capistranorb.com ➤ heroku.com ➤ tryruby.org ➤ awesome-ruby.com ➤ helloruby.com ➤ rubysec.com ➤ jetbrains.com/ruby/ ➤ sinatrarb.com ➤ hanamirb.org ➤ voltframework.com ➤ rubyinstaller.org (windows)