SlideShare a Scribd company logo
THE TEN 
COMMANDMENTS 
of the ruby programmer
I AM EMILIO A RUBY PROGRAMMER 
Software developer +15 yrs 
10Pines founder 
Agiles community founding member 
agiles 2012 conference co-chair 
husband, father and homeBrewer
I. Thou shalt have no 
domain objects coupled 
with thy frameworks
class Speaker < ActiveRecord::Base 
! 
devise :omniauthable, 
:omniauth_providers => [:facebook] 
! 
def approve_session(session) 
# do something 
SessionMailer.approve(speaker: self, 
session: session).deliver 
end 
! 
end
II. THOU SHALT NOT 
STEAL & PASTE CODE
public List selectPending(List registrations) { 
! 
List pending = new ArrayList(); 
for (Registration registration: registrations) { 
if (!registration.isPaid()) { 
pending.add(registration); 
} 
} 
return pending; 
}
! 
def select_pending(registrations) 
registrations.reject(&:paid?) 
end 
! 
!
class SessionsController < ApplicationController 
! 
def create 
! 
@session = Session.new(session_params) 
! 
if @session.save 
redirect_to my_sessions_path, 
notice: 'Session created successfully' 
else 
render :new 
end 
! 
end 
end
class Program 
! 
def find_by_author(author) 
! 
sessions = Session.where(author: author, 
approved: true) 
! 
if sessions.empty? 
# do something 
else 
# do something 
end 
end 
! 
end
III. THOU SHALT 
NOT USE NIL
class AttendeePresenter 
! 
def phone_number 
! 
unless self.address.nil? 
unless self.address.phone_number.nil? 
self.address.phone_number 
else 
'Phone number not present' 
end 
else 
'Address not present' 
end 
end 
! 
end
class Attendee 
def initialize(address) 
if address.nil? 
raise ArgumentError, 'Address is required' 
end 
@address = address 
end 
! 
def address 
@address || UnknownAddress.new 
end 
! 
def phone_number 
Optional.new(@address). 
within {|address| address.phone_number} 
end 
end
IV. THOU SHALT 
NOT USE IF
class BankAccount 
! 
def process a_transaction 
! 
if a_transaction.type == :purchase 
# charge transaction fee 
else 
# assume refund 
end 
end 
! 
end
class BankAccount 
! 
def process a_transaction 
a_transaction.process self 
end 
! 
def process_purchase a_transaction 
# charge transaction fee 
end 
! 
def process_refund a_transaction 
# refund transaction fee 
end 
! 
end
class Purchase < Transaction 
! 
def process a_payment_method 
a_payment_method.process_purchase self 
end 
end 
! 
class Refund < Transaction 
! 
def process a_payment_method 
a_payment_method.process_refund self 
end 
end
V. THOU SHALT 
NOT MOCK
require 'spec_helper' 
! 
describe Registration do 
! 
it 'pays a registration' do 
! 
attendee_id = 1 
a_registration = double("Registration") 
an_attendee = double("Attendee", registration: a_registration) 
! 
allow(Attendee).to receive(:find) { an_attendee } 
! 
expect(a_registration).to receive(:paid=).with(true) 
expect(a_registration).to receive(:save).and_return(true) 
! 
expect_any_instance_of(PaypalAccount).to receive(:process) 
! 
Registration.pay(attendee_id) 
! 
end 
end
VI. THOU SHALT NOT TAKE 
THY TESTS 
IN VAIN
VI. THOU SHALT NOT TAKE 
THY 
IN VAIN 
VII. REMEMBER TO 
REFACTOR EVERY DAY
VI. THOU SHALT NOT TAKE 
THY 
IN VAIN 
VII. REMEMBER TO 
REFACTOR 
VII. THOU SHALT BEAR YOUR 
FELLOW PROGRAMMERS 
AND PAIR WITH THEM
IX. CHALLENGE 
HONOUR 
/[RUBY|RAILS|.*]/ 
FATHER AND MOTHER
X. NO GRAVEN 
PRACTICES
QUESTIONS? 
comments, critics, 
compliments
THANKS!!! 
email: egutter@10pines.com 
twitter: @10pines 
site: dev.10pines.com 
blog: blog.10pines.com

More Related Content

Viewers also liked (14)

Ann of websites
Ann of websitesAnn of websites
Ann of websites
 
Harry Mylonas, Driving networks into their all-IP future
Harry Mylonas, Driving networks into their all-IP futureHarry Mylonas, Driving networks into their all-IP future
Harry Mylonas, Driving networks into their all-IP future
 
10pines - about us
10pines - about us10pines - about us
10pines - about us
 
Presentasi bloetooth
Presentasi bloetoothPresentasi bloetooth
Presentasi bloetooth
 
Mikkeli 20 V 300909 Nettiin
Mikkeli 20 V 300909 NettiinMikkeli 20 V 300909 Nettiin
Mikkeli 20 V 300909 Nettiin
 
Mobile Networks - Evolving to all-IP Backbone
Mobile Networks - Evolving to all-IP BackboneMobile Networks - Evolving to all-IP Backbone
Mobile Networks - Evolving to all-IP Backbone
 
Agiles2008 - Distributed Agile
Agiles2008 - Distributed AgileAgiles2008 - Distributed Agile
Agiles2008 - Distributed Agile
 
Evaluation and audience feedback
Evaluation and audience feedbackEvaluation and audience feedback
Evaluation and audience feedback
 
Erosion
ErosionErosion
Erosion
 
Guanajuato
GuanajuatoGuanajuato
Guanajuato
 
Project Pitch
Project PitchProject Pitch
Project Pitch
 
Mikkelihoitonytjatulevaisuudessa300909eikuv
Mikkelihoitonytjatulevaisuudessa300909eikuvMikkelihoitonytjatulevaisuudessa300909eikuv
Mikkelihoitonytjatulevaisuudessa300909eikuv
 
Guanajuato
Guanajuato Guanajuato
Guanajuato
 
Newspaper proposal
Newspaper proposalNewspaper proposal
Newspaper proposal
 

Similar to Rubyconf2014

Ruby on Rails For Java Programmers
Ruby on Rails For Java ProgrammersRuby on Rails For Java Programmers
Ruby on Rails For Java Programmers
elliando dias
 
Behavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWestBehavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWest
Joshua Warren
 
Refactoring in Practice - Sunnyconf 2010
Refactoring in Practice - Sunnyconf 2010Refactoring in Practice - Sunnyconf 2010
Refactoring in Practice - Sunnyconf 2010
Alex Sharp
 

Similar to Rubyconf2014 (20)

Programmers slang
Programmers slangProgrammers slang
Programmers slang
 
Ruby on Rails For Java Programmers
Ruby on Rails For Java ProgrammersRuby on Rails For Java Programmers
Ruby on Rails For Java Programmers
 
Staying railsy - while scaling complexity or Ruby on Rails in Enterprise Soft...
Staying railsy - while scaling complexity or Ruby on Rails in Enterprise Soft...Staying railsy - while scaling complexity or Ruby on Rails in Enterprise Soft...
Staying railsy - while scaling complexity or Ruby on Rails in Enterprise Soft...
 
Where Does the Fat Goes? Utilizando Form Objects Para Simplificar seu Código
Where Does the Fat Goes? Utilizando Form Objects Para Simplificar seu CódigoWhere Does the Fat Goes? Utilizando Form Objects Para Simplificar seu Código
Where Does the Fat Goes? Utilizando Form Objects Para Simplificar seu Código
 
Php Tutorial | Introduction Demo | Basics
 Php Tutorial | Introduction Demo | Basics Php Tutorial | Introduction Demo | Basics
Php Tutorial | Introduction Demo | Basics
 
Learning of Php and My SQL Tutorial | For Beginners
Learning of Php and My SQL Tutorial | For BeginnersLearning of Php and My SQL Tutorial | For Beginners
Learning of Php and My SQL Tutorial | For Beginners
 
Php My SQL Tutorial | beginning
Php My SQL Tutorial | beginningPhp My SQL Tutorial | beginning
Php My SQL Tutorial | beginning
 
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
The worst Ruby codes I’ve seen in my life - RubyKaigi 2015
 
Phone calls and sms from php
Phone calls and sms from phpPhone calls and sms from php
Phone calls and sms from php
 
Rails antipatterns
Rails antipatternsRails antipatterns
Rails antipatterns
 
Rails antipattern-public
Rails antipattern-publicRails antipattern-public
Rails antipattern-public
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
Multi tenant/lang application with Ruby on Rails
Multi tenant/lang application with Ruby on RailsMulti tenant/lang application with Ruby on Rails
Multi tenant/lang application with Ruby on Rails
 
PHPSpec & Behat: Two Testing Tools That Write Code For You (#phptek edition)
PHPSpec & Behat: Two Testing Tools That Write Code For You (#phptek edition)PHPSpec & Behat: Two Testing Tools That Write Code For You (#phptek edition)
PHPSpec & Behat: Two Testing Tools That Write Code For You (#phptek edition)
 
Heroku addons development - Nov 2011
Heroku addons development - Nov 2011Heroku addons development - Nov 2011
Heroku addons development - Nov 2011
 
Refactoring
RefactoringRefactoring
Refactoring
 
Behavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWestBehavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWest
 
Refactoring in Practice - Sunnyconf 2010
Refactoring in Practice - Sunnyconf 2010Refactoring in Practice - Sunnyconf 2010
Refactoring in Practice - Sunnyconf 2010
 
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
 
Php mysql
Php mysqlPhp mysql
Php mysql
 

Recently uploaded

Recently uploaded (20)

Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting software
 
Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
iGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by SkilrockiGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by Skilrock
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
 
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM Integration
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
AI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning Framework
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in Michelangelo
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
 
GraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysisGraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysis
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdfA Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Breaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdfBreaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdf
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 

Rubyconf2014

  • 1. THE TEN COMMANDMENTS of the ruby programmer
  • 2. I AM EMILIO A RUBY PROGRAMMER Software developer +15 yrs 10Pines founder Agiles community founding member agiles 2012 conference co-chair husband, father and homeBrewer
  • 3. I. Thou shalt have no domain objects coupled with thy frameworks
  • 4. class Speaker < ActiveRecord::Base ! devise :omniauthable, :omniauth_providers => [:facebook] ! def approve_session(session) # do something SessionMailer.approve(speaker: self, session: session).deliver end ! end
  • 5. II. THOU SHALT NOT STEAL & PASTE CODE
  • 6. public List selectPending(List registrations) { ! List pending = new ArrayList(); for (Registration registration: registrations) { if (!registration.isPaid()) { pending.add(registration); } } return pending; }
  • 7. ! def select_pending(registrations) registrations.reject(&:paid?) end ! !
  • 8. class SessionsController < ApplicationController ! def create ! @session = Session.new(session_params) ! if @session.save redirect_to my_sessions_path, notice: 'Session created successfully' else render :new end ! end end
  • 9. class Program ! def find_by_author(author) ! sessions = Session.where(author: author, approved: true) ! if sessions.empty? # do something else # do something end end ! end
  • 10. III. THOU SHALT NOT USE NIL
  • 11. class AttendeePresenter ! def phone_number ! unless self.address.nil? unless self.address.phone_number.nil? self.address.phone_number else 'Phone number not present' end else 'Address not present' end end ! end
  • 12. class Attendee def initialize(address) if address.nil? raise ArgumentError, 'Address is required' end @address = address end ! def address @address || UnknownAddress.new end ! def phone_number Optional.new(@address). within {|address| address.phone_number} end end
  • 13. IV. THOU SHALT NOT USE IF
  • 14. class BankAccount ! def process a_transaction ! if a_transaction.type == :purchase # charge transaction fee else # assume refund end end ! end
  • 15. class BankAccount ! def process a_transaction a_transaction.process self end ! def process_purchase a_transaction # charge transaction fee end ! def process_refund a_transaction # refund transaction fee end ! end
  • 16. class Purchase < Transaction ! def process a_payment_method a_payment_method.process_purchase self end end ! class Refund < Transaction ! def process a_payment_method a_payment_method.process_refund self end end
  • 17. V. THOU SHALT NOT MOCK
  • 18. require 'spec_helper' ! describe Registration do ! it 'pays a registration' do ! attendee_id = 1 a_registration = double("Registration") an_attendee = double("Attendee", registration: a_registration) ! allow(Attendee).to receive(:find) { an_attendee } ! expect(a_registration).to receive(:paid=).with(true) expect(a_registration).to receive(:save).and_return(true) ! expect_any_instance_of(PaypalAccount).to receive(:process) ! Registration.pay(attendee_id) ! end end
  • 19. VI. THOU SHALT NOT TAKE THY TESTS IN VAIN
  • 20. VI. THOU SHALT NOT TAKE THY IN VAIN VII. REMEMBER TO REFACTOR EVERY DAY
  • 21. VI. THOU SHALT NOT TAKE THY IN VAIN VII. REMEMBER TO REFACTOR VII. THOU SHALT BEAR YOUR FELLOW PROGRAMMERS AND PAIR WITH THEM
  • 22. IX. CHALLENGE HONOUR /[RUBY|RAILS|.*]/ FATHER AND MOTHER
  • 23. X. NO GRAVEN PRACTICES
  • 25. THANKS!!! email: egutter@10pines.com twitter: @10pines site: dev.10pines.com blog: blog.10pines.com