68
Ruby on Rails 3.1 Let’s bring the fun back to web programming! presents Bozhidar Batsov Technical Lead

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

Embed Size (px)

DESCRIPTION

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

Citation preview

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

Ruby on Rails 3.1Let’s bring the fun back to web programming!

presents

Bozhidar BatsovTechnical Lead

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

The problem

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

Many programmers are not particularly happy

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

It's the question that drives us, Neo. It's the question that brought you here. You know the question, just as I did.

What is the question?

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

How can I be be one happy

(web) programmer?

Page 6: Ruby on Rails 3.1: Let's bring the fun back into web programing
Page 7: Ruby on Rails 3.1: Let's bring the fun back into web programing
Page 8: Ruby on Rails 3.1: Let's bring the fun back into web programing

VS. VS.

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

VS. VS.

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

This PHP code is so clean and elegantly solves the problem at hand.

Nobody, Never

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

0 10 20 30 40 50 60 70 80 90 100OOP

FP

Performance

Productivity

Fun

PHP

Page 13: Ruby on Rails 3.1: Let's bring the fun back into web programing
Page 14: Ruby on Rails 3.1: Let's bring the fun back into web programing
Page 15: Ruby on Rails 3.1: Let's bring the fun back into web programing

There should be one – and preferably only one – obvious way to do it.

The Zen of Python

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

0 10 20 30 40 50 60 70 80 90 100OOP

FP

Performance

Productivity

Fun

Python

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

The Web framework for perfectionists with

deadlines.

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

2007

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

A Programmer’s Best Friend

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

The goal of Ruby is to make programmers happy. I started out to make a programming language that would make me happy, and as a side effect it’s made many, many programmers happy. Especially Web developers.

Yukihiro “Matz” Matsumoto,creator of Ruby

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

0 10 20 30 40 50 60 70 80 90 100

OOP

FP

Performance

Productivity

Fun

Ruby

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

0 10 20 30 40 50 60 70 80 90 100

OOP

FP

Performance

Productivity

Fun

PHP Python Ruby

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

0369

12

15

18

21

24

27

30

JQueryDjango

Ruby on Rails

Startup Technologies 2011

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

http://www.ruby-toolbox.com

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

“Rails is the most well thought-out web development framework I’ve ever used. And

that’s in a decade of doing web applications for a living. I’ve built my own frameworks, helped

develop 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

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

“Ruby on Rails is a breakthrough in lowering the barriers of entry to

programming. Powerful web applications that formerly might have taken weeks or months to develop can

be produced in a matter of days.”

Tim O'Reilly, Founder of O'Reilly Media

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

“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

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

“Rails is the killer app for Ruby.”

Yukihiro Matsumoto, Creator of Ruby

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

Convention over

Configuration

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

DRY(Don’t repeat

yourself)

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

Many view (template) options

#profile .left.column #date= print_date #address= current_user.address .right.column #email= current_user.email #bio= current_user.bio

<div id="profile"> <div class="left column"> <div id="date"><%= print_date %></div> <div id="address"><%= current_user.address %></div> </div> <div class="right column"> <div id="email"><%= current_user.email %></div> <div id="bio"><%= current_user.bio %></div> </div></div>

HamlHTML + Erb

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

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 some inventory. Thank you!

div id="footer" | Copyright © 2010 Andrew Stone

= render 'tracking_code'

javascript: $(content).do_something();

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

Testing in Rails is not optional!

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

All the code is guilty until

proven innocent!

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

DSL FTW

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

class 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

ActiveRecord

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

XML Freedevelopment: adapter: postgresql database: mycoolproject host: localhost username: mycoolproject password: mycoolproject encoding: utf8

test: adapter: sqlite3 database: db/test.sqlite3 pool: 5 timeout: 5000

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

rails g (generate)

rails c (console)

rails db (dbconsole)

rake

bundle

UNIX Certified

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

Agile

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

Innovation

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

Lots of friends

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

Fork me on GitHub!

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

Fantastic documentation

RailsGuides (http://guide.rubyonrails.org)

RailsCasts (http://railscasts.org)

PragProg

Ruby on Rails 3 Tutorial (http://ruby.railstutorial.org/)

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

The Dark Art of Deployment

Page 50: Ruby on Rails 3.1: Let's bring the fun back into web programing
Page 51: Ruby on Rails 3.1: Let's bring the fun back into web programing
Page 52: Ruby on Rails 3.1: Let's bring the fun back into web programing

In the clouds...

?

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

$ heroku create --stack cedar$ git push heroku master$ heroku open$ heroku scale web=100 worker=50

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

Happy programmers

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

Rails 3.1

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

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)

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

var 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;})();

JavaScript

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

Asset Pipeline

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

SASS$blue: #3bbfce;$margin: 16px;

.content-navigation { border-color: $blue; color: darken($blue, 9%);}

.border { padding: $margin / 2; margin: $margin / 2; border-color: $blue;}

.content-navigation { border-color: #3bbfce; color: #2b9eab;}

.border { padding: 8px; margin: 8px; border-color: #3bbfce;}

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

table.hl { margin: 2em 0; td.ln { text-align: right; }}

li { font: { family: serif; weight: bold; size: 1.2em; }}

table.hl { margin: 2em 0;}table.hl td.ln { text-align: right;}

li { font-family: serif; font-weight: bold; font-size: 1.2em;}

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

@mixin table-base { th { text-align: center; font-weight: bold; } td, th {padding: 2px}}

@mixin left($dist) { float: left; margin-left: $dist;}

#data { @include left(10px); @include table-base;}

#data { float: left; margin-left: 10px;}#data th { text-align: center; font-weight: bold;}#data td, #data th { padding: 2px;}

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

.error { border: 1px #f00; background: #fdd;}.error.intrusion { font-size: 1.3em; font-weight: bold;}

.badError { @extend .error; border-width: 3px;}

.error, .badError { border: 1px #f00; background: #fdd;}

.error.intrusion,

.badError.intrusion { font-size: 1.3em; font-weight: bold;}

.badError { border-width: 3px;}

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

Always in motion the future is...

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

Rails 4.0

targeting Ruby 1.9.2

expected in an year

it will be the end of the world as we know it :-)

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

Q & A(any questions?!)

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

Thanks!

Don’t leave just yet ;-)