Ruby on Rails 3.1: Let's bring the fun back into web programing

1,856 views
1,723 views

Published on

The first talk from the "Empower on Rails" Ruby on Rails seminars.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,856
On SlideShare
0
From Embeds
0
Number of Embeds
34
Actions
Shares
0
Downloads
14
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Ruby on Rails 3.1: Let's bring the fun back into web programing

  1. 1. presents Ruby on Rails 3.1Let’s bring the fun back to web programming! Bozhidar Batsov Technical Lead
  2. 2. The problem
  3. 3. Many programmers arenot particularly happy
  4. 4. Its the question that drivesus, Neo. Its the question that brought you here. You know the question, just as I did. What is the question?
  5. 5. How can I be be one happy(web) programmer?
  6. 6. VS. VS.
  7. 7. VS. VS.
  8. 8. This PHP code is soclean and elegantlysolves the problem athand. Nobody, Never
  9. 9. PHP 0 10 20 30 40 50 60 70 80 90 100 OOP FPPerformance Productivity Fun
  10. 10. The Zen of PythonThere should be one –and preferably only one– obvious way to do it.
  11. 11. Python 0 10 20 30 40 50 60 70 80 90 100 OOP FPPerformanceProductivity Fun
  12. 12. The Web framework for perfectionists with deadlines.
  13. 13. 2007
  14. 14. A Programmer’s Best Friend
  15. 15. The goal of Ruby is to makeprogrammers happy. I started outto make a programming language thatwould make me happy, and as a sideeffect it’s made many, many programmershappy. Especially Webdevelopers. Yukihiro “Matz” Matsumoto, creator of Ruby
  16. 16. Ruby 0 10 20 30 40 50 60 70 80 90 100 OOP FPPerformance Productivity Fun
  17. 17. PHP Python Ruby 0 10 20 30 40 50 60 70 80 90 100 OOP FPPerformance Productivity Fun
  18. 18. Startup Technologies 2011 30 27 24 21 18 15 12 9 6JQuery 3 Django 0 Ruby on Rails
  19. 19. http://www.ruby-toolbox.com
  20. 20. “Rails is the most well thought-out web development framework I’ve ever used. Andthat’s in a decade of doing web applications fora living. I’ve built my own frameworks, helpeddevelop the Servlet API, and have created more than a few web servers from scratch. Nobody has done it like this before.” James Duncan Davidson, Creator of Tomcat and Ant
  21. 21. “Ruby on Rails is a breakthrough in lowering the barriers of entry to programming. Powerful webapplications that formerly might havetaken weeks or months to develop can be produced in a matter of days.” Tim OReilly, Founder of OReilly Media
  22. 22. “It is impossible not to notice Ruby on Rails. It has had a huge effect both in and outside the Ruby community...Rails has become a standard to which even well-established tools are comparing themselves to.” Martin Fowler, Author of - Refactoring, PoEAA, XP Explained
  23. 23. “Rails is the killer app for Ruby.” Yukihiro Matsumoto, Creator of Ruby
  24. 24. Convention overConfiguration
  25. 25. DRY (Don’t repeatyourself)
  26. 26. Many view (template) options HTML + Erb Haml<div id="profile"> #profile <div class="left column"> .left.column <div id="date"><%= print_date %></div> #date= print_date <div id="address"><%= current_user.address %></div> #address= current_user.address </div> .right.column <div class="right column"> #email= current_user.email <div id="email"><%= current_user.email %></div> #bio= current_user.bio <div id="bio"><%= current_user.bio %></div> </div></div>
  27. 27. doctype htmlhtml head title Slim Core Example meta name="keywords" content="template language" body h1 Markup examples div id="content" class="example1" p Nest by indentation == yield - unless items.empty? table - for item in items do tr td = item.name td = item.price - else p | No items found. Please add someinventory. Thank you! div id="footer" | Copyright © 2010 Andrew Stone = render tracking_code javascript: $(content).do_something();
  28. 28. Testing in Rails is not optional!
  29. 29. All the codeis guilty until proven innocent!
  30. 30. DSL FTW
  31. 31. ActiveRecordclass Page < ActiveRecord::Base has_many :page_images, :dependent => :destroy validates :title, :presence => true, :uniqueness => true validates :content, :presence => true validates :permalink, :presence => true, :uniqueness => true accepts_nested_attributes_for :page_images, :allow_destroy => true def to_param permalink endend
  32. 32. XML Free development: adapter: postgresql database: mycoolproject host: localhost username: mycoolproject password: mycoolproject encoding: utf8 test: adapter: sqlite3 database: db/test.sqlite3 pool: 5 timeout: 5000
  33. 33. UNIX Certifiedrails g (generate)rails c (console)rails db (dbconsole)rakebundle
  34. 34. Agile
  35. 35. Innovation
  36. 36. Lots offriends
  37. 37. Fo r k me on Git Hu b!
  38. 38. Fantastic documentationRailsGuides (http://guide.rubyonrails.org)RailsCasts (http://railscasts.org)PragProgRuby on Rails 3 Tutorial (http://ruby.railstutorial.org/)
  39. 39. The Dark Art of Deployment
  40. 40. In the clouds... ?
  41. 41. $ heroku create --stack cedar$ git push heroku master$ heroku open$ heroku scale web=100 worker=50
  42. 42. Happy programmers
  43. 43. Rails 3.1
  44. 44. CoffeeScript# Assignment:number = 42opposite = true# Conditions:number = -42 if opposite# Functions:square = (x) -> x * x# Arrays:list = [1, 2, 3, 4, 5]# Objects:math = root: Math.sqrt square: square cube: (x) -> x * square x# Splats:race = (winner, runners...) -> print winner, runners# Existence:alert "I knew it!" if elvis?# Array comprehensions:cubes = (math.cube num for num in list)
  45. 45. JavaScriptvar cubes, list, math, num, number, opposite, race, square;var __slice = Array.prototype.slice;number = 42;opposite = true;if (opposite) number = -42;square = function(x) { return x * x;};list = [1, 2, 3, 4, 5];math = { root: Math.sqrt, square: square, cube: function(x) { return x * square(x); }};race = function() { var runners, winner; winner = arguments[0], runners = 2 <= arguments.length ? __slice.call(arguments, 1) : []; return print(winner, runners);};if (typeof elvis !== "undefined" && elvis !== null) alert("I knew it!");cubes = (function() { var _i, _len, _results; _results = []; for (_i = 0, _len = list.length; _i < _len; _i++) { num = list[_i]; _results.push(math.cube(num)); } return _results;})();
  46. 46. Asset Pipeline
  47. 47. SASS$blue: #3bbfce; .content-navigation {$margin: 16px; border-color: #3bbfce; color: #2b9eab;.content-navigation { } border-color: $blue; color: .border { darken($blue, 9%); padding: 8px;} margin: 8px; border-color: #3bbfce;.border { } padding: $margin / 2; margin: $margin / 2; border-color: $blue;}
  48. 48. table.hl { table.hl { margin: 2em 0; margin: 2em 0; td.ln { } text-align: right; table.hl td.ln { } text-align: right;} }li { li { font: { font-family: serif; family: serif; font-weight: bold; weight: bold; font-size: 1.2em; size: 1.2em; } }}
  49. 49. @mixin table-base { #data { th { float: left; text-align: center; margin-left: 10px; font-weight: bold; } } #data th { td, th {padding: 2px} text-align: center;} font-weight: bold; }@mixin left($dist) { #data td, #data th { float: left; padding: 2px; margin-left: $dist; }}#data { @include left(10px); @include table-base;}
  50. 50. .error { .error, .badError { border: 1px #f00; border: 1px #f00; background: #fdd; background: #fdd;} }.error.intrusion { .error.intrusion, font-size: 1.3em; .badError.intrusion font-weight: bold; {} font-size: 1.3em;.badError { font-weight: bold; @extend .error; } border-width: 3px; .badError {} border-width: 3px; }
  51. 51. Always in motion the future is...
  52. 52. Rails 4.0targeting Ruby 1.9.2expected in an yearit will be the end of the world as we knowit :-)
  53. 53. About Bozhidarbozhidar@empowerunited.comhttp://batsov.com@bbatsovhttp://github.com/bbatsov
  54. 54. Q&A(any questions?!)
  55. 55. Thanks!Don’t leave just yet ;-)
  56. 56. you@empowerunited.comfacebook.com/empoweronrails

×