SlideShare a Scribd company logo
1 of 77
Download to read offline
RAILS IS FROM MARS
RUBY IS FROM VENUS
Relationship Advice For Rails Developers
WHO AM I?
• My    name is Rein Henrichs.

• That’s   pronounced like “rain”.

• But   spelled differently.

•I   work at

•I   blog at reinh.com

•I   twitter @reinh

•I   like candlelit dinners and long walks on the beach.
insert logo
        here
          :(




YOU KNOW RAILS
BUT DO YOU KNOW RUBY?
How many people here use Rails?
How many of you think you know
 Ruby as well as you know Rails?
How many of you have
contributed to an open-source
        Ruby project?
How many of you have
written your own gem?
How many of you would be
comfortable writing an HTTP
   client library in Ruby?
How many of you could write
 your own web framework?
WHY SHOULD I LEARN RUBY?


• It’s   easy.

• It’s   fun.

• It   will make you better at Rails.

• It   will make you a better person.
HOW DO I LEARN RUBY?
      Some resources
Free stuff
WHY’S POIGNANT GUIDE
 It has cartoon foxes. Foxen? It has cartoon foxen.
PROGRAMMING RUBY
     a.k.a. The Pickaxe
MR. NEIGHBORLY’S
  HUMBLE LITTLE
RUBY BOOK
Pragmatically chunky bacon
Not so free stuff
(but still really good)
RUBY IN A
NUTSHELL
Come on. Matz wrote it.
RUBY IN
     PRACTICE
Look at that funny looking guy
on the cover. At least it’s not a
 nasty monkey. Sorry, O’Reilly
THE RUBY
  WAY
RUBY FOR
  RAILS
THE WELL-
GROUNDED
  RUBYIST
RAILS HAS OPINIONS
    And Ruby Likes To Talk
Rails is opinionated software
Ruby is a communicative language
Sometimes, Ruby just wants
  someone to listen to it.
If you’re programming along, doing nicely, and
all of a sudden your program gets balky, makes
things hard for you, it’s talking. It’s telling you
there is something important missing.
     – Kent Beck, Smalltalk Best Practice Patterns
It is your responsibility to
listen to your code and be
  considerate of its needs.
Write Ruby code that
communicates well but be
respectful of Rails’ opinions
Other people who use your code
 (including six-months-later you)
          will thank you.
Ruby makes it easy to write
simply, clearly and expressively
Rails has powerful idioms
     and conventions
Combining the two makes for a
  happy, fulfilling relationship
RUBY LOVES YOU
But Sometimes You Drive Her Crazy
These are some of the things you
    do that drive Ruby crazy.
You’re welcome.
# Bad
i = 0; while i < array.size do
  puts array[i]
  i += 1
end

# Better
for item in array
  puts item
end

# Best
array.each do |item|
  puts item
end
WHY?


• Ruby   has powerful iterators.

• You   don’t need to write your own.

         ... in ... just calls #each internally.
• for
# Bad
value = value ? value : quot;defaultquot;

# Better
value = value || quot;defaultquot;

# Best
value ||= quot;defaultquot;
WHY?



• Ternaries   (the ? : thing) are ugly.

• Ruby   has pretty assignment with operators like += and ||=
# Bad
array << 42 unless array.include?(42)
array = array + [42] unless array.include?(42)

# Better
array = array | [42]

# Best
array |= [42]
WHY?



• Sometimes   it just helps to know what set union is.
# Bad
if value != nil && value != false

# Good
if value
WHY?



• Ruby   has a sane notion of truthiness
# Bad
if value == 1 || value == 12 || value == 42

# Good
if [1,12,42].include? value
WHY?


• Brevity   is not the goal

• Readability   is the goal

• But   if it is more readable and also shorter, go for it.
# Bad
def request
  begin
    perform_request
  rescue RequestError => e
    log_error e
  end
end

# Good
def request
  perform_request
rescue RequestError => e
  log_error e
end
WHY?



• Method   definitions are an implied begin block.
# Bad
!!value

# Good
value
WHY?



• Ruby   does not not like clarity.

• What   you lose in readability you gain in nothing.
# Bad
ActiveRecord::Base

# Good
ActiveRecord::Model
WHY?


• Naming    things is important.

• Base? What    does that even mean?

• Sorry   Rails, you got this one wrong. Better luck next time.
# Bad
class PostsController < ApplicationController
  def recent
    Post.find :all,
              :conditions => ['posts.created_at > ?',
                              1.week.ago]
  end
end
# Good
class PostsController < ApplicationController
  def recent
    Post.within 1.week
  end
end
class Post < ActiveRecord::Base
  named_scope :within,
    lambda {|seconds| :conditions => ['posts.created_at > ?',
                                      seconds.ago]}
end
WHY?


• Make    your code more expressive

• And    more intention revealing.

• In   other words, say what you mean to say.
url_for(:blog, :posts, @post.id, :comments, :replies => true)
# => http://example.com/blog/posts/19/comments?replies=true
# Bad
def url_for(*args)
  root + args.map{|arg| parse_arg(arg)}.join('/').
    gsub('/?', '?')
end

def parse_arg(arg)
  case arg
  when Array: arg.join('/')
  when Hash
    ret = []
    each{|k,v| ret << quot;#{k}=#{v}quot;}
    ret = ret.join('&')
    '?' + ret
  else: arg.to_s
  end
end
# Good
def url_for(*args)
  root + args.to_params
end
class Array
  def to_params
    map{|a| a.to_params}.join('/').
      gsub('/?', '?')
  end
end
# Array
%w(foo bar bazz).to_params # quot;/foo/bar/bazzquot;

# Hash
{:foo => :bar}.to_params # quot;?foo=barquot;
WHY?

• Ruby   uses coercion in many places

 • 1.to_s

 • (1..10).to_a

• Writingyour own coercion method can help you use Ruby’s
 ducktyping.

• Separation   of concerns.
RAILS PERFORMANCE
Insert your “scaling” and “premature optimization” jokes here.
Yes, I went there.
Slow is only meaningful
    in comparison.
Ruby is slow? Compared to what?
Is your database slow?
Are your views slow?
Is your app server slow?
Are you using HTTP
 via carrier pigeon?
If you don’t know where the slow
  is, you’re not ready to optimize.
Don’t optimize prematurely, but
    don’t pessimize either.
Don’t write code you know will
      never, ever be fast.
# Really Bad (Optimally Pessimum)
class Ballot < ActiveRecord::Base
  def <=>(other)
    votes.count <=> other.votes.count
  end
end

# Good (Potentially Optimum)
class Ballot < ActiveRecord::Base
  # With a counter_cache on votes
  default_scope :order => :votes_count
end
IN OTHER WORDS


• Don’t   worry about speed until you know where the slow is.

• Worry    about writing simply and expressively.

• Well   written code is easy to optimize for performance later.

• Don’t   write something you know will never, ever be fast.
IN CONCLUSION

• Ruby    is fun and easy (and friendly!).

• Ruby    will make you happy.

• Be    more thoughtful in the way you treat Ruby.

• The    more Ruby you know, the better you can become at Rails.

• If   you love Rails, you should love Ruby too.

• Also, don’t   be premature. No one likes that.
WHO AM I?
• My    name is Rein Henrichs.

• That’s   pronounced like “rain”.

• But   spelled differently.

•I   work at

•I   blog at reinh.com

•I   twitter @reinh

•I   like candlelit dinners and long walks on the beach.

More Related Content

Similar to Rails Is From Mars Ruby Is From Venus Presentation 1

When To Use Ruby On Rails
When To Use Ruby On RailsWhen To Use Ruby On Rails
When To Use Ruby On Railsdosire
 
Ruby for .NET developers
Ruby for .NET developersRuby for .NET developers
Ruby for .NET developersMax Titov
 
Better Perl Practices
Better Perl PracticesBetter Perl Practices
Better Perl PracticesJay Shirley
 
Ruby Rails Overview
Ruby Rails OverviewRuby Rails Overview
Ruby Rails OverviewNetguru
 
All I want for Matz-mas
All I want for Matz-masAll I want for Matz-mas
All I want for Matz-masAndrew Grimm
 
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Aslak Hellesøy
 
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Aslak Hellesøy
 
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Aslak Hellesøy
 
Culture And Aesthetic Revisited
Culture And Aesthetic RevisitedCulture And Aesthetic Revisited
Culture And Aesthetic RevisitedAdam Keys
 
Intro to Ruby/Rails at TechLady Hackathon
Intro to Ruby/Rails at TechLady HackathonIntro to Ruby/Rails at TechLady Hackathon
Intro to Ruby/Rails at TechLady Hackathonkdmcclin
 
Rails Development That Doesn't Hurt
Rails Development That Doesn't HurtRails Development That Doesn't Hurt
Rails Development That Doesn't HurtAkira Matsuda
 
Arulalan Ruby An Intro
Arulalan  Ruby An IntroArulalan  Ruby An Intro
Arulalan Ruby An IntroArulalan T
 
Learning To Walk In Shoes
Learning To Walk In ShoesLearning To Walk In Shoes
Learning To Walk In ShoesBrian Hogan
 

Similar to Rails Is From Mars Ruby Is From Venus Presentation 1 (20)

When To Use Ruby On Rails
When To Use Ruby On RailsWhen To Use Ruby On Rails
When To Use Ruby On Rails
 
Ruby for .NET developers
Ruby for .NET developersRuby for .NET developers
Ruby for .NET developers
 
Better Perl Practices
Better Perl PracticesBetter Perl Practices
Better Perl Practices
 
Mlw
MlwMlw
Mlw
 
Ruby Rails Overview
Ruby Rails OverviewRuby Rails Overview
Ruby Rails Overview
 
Couch DB from 10 000 ft
Couch DB from 10 000 ftCouch DB from 10 000 ft
Couch DB from 10 000 ft
 
All I want for Matz-mas
All I want for Matz-masAll I want for Matz-mas
All I want for Matz-mas
 
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009
 
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009
 
Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009Ruby presentasjon på NTNU 22 april 2009
Ruby presentasjon på NTNU 22 april 2009
 
Culture And Aesthetic Revisited
Culture And Aesthetic RevisitedCulture And Aesthetic Revisited
Culture And Aesthetic Revisited
 
Rails console
Rails consoleRails console
Rails console
 
Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentation
 
Intro to Ruby/Rails at TechLady Hackathon
Intro to Ruby/Rails at TechLady HackathonIntro to Ruby/Rails at TechLady Hackathon
Intro to Ruby/Rails at TechLady Hackathon
 
Rails Development That Doesn't Hurt
Rails Development That Doesn't HurtRails Development That Doesn't Hurt
Rails Development That Doesn't Hurt
 
Arulalan Ruby An Intro
Arulalan  Ruby An IntroArulalan  Ruby An Intro
Arulalan Ruby An Intro
 
Meet ruby
Meet rubyMeet ruby
Meet ruby
 
Learning To Walk In Shoes
Learning To Walk In ShoesLearning To Walk In Shoes
Learning To Walk In Shoes
 
Learning Ruby
Learning RubyLearning Ruby
Learning Ruby
 
Ruby
RubyRuby
Ruby
 

More from railsconf

Smacking Git Around Advanced Git Tricks
Smacking Git Around   Advanced Git TricksSmacking Git Around   Advanced Git Tricks
Smacking Git Around Advanced Git Tricksrailsconf
 
Running The Show Configuration Management With Chef Presentation
Running The Show  Configuration Management With Chef PresentationRunning The Show  Configuration Management With Chef Presentation
Running The Show Configuration Management With Chef Presentationrailsconf
 
Sd208 Ds%2 C0
Sd208 Ds%2 C0Sd208 Ds%2 C0
Sd208 Ds%2 C0railsconf
 
Rails 3 And The Real Secret To High Productivity Presentation
Rails 3 And The Real Secret To High Productivity PresentationRails 3 And The Real Secret To High Productivity Presentation
Rails 3 And The Real Secret To High Productivity Presentationrailsconf
 
Quality Code With Cucumber Presentation
Quality Code With Cucumber PresentationQuality Code With Cucumber Presentation
Quality Code With Cucumber Presentationrailsconf
 
J Ruby On Rails Presentation
J Ruby On Rails PresentationJ Ruby On Rails Presentation
J Ruby On Rails Presentationrailsconf
 
Gov 2 0 Transparency Collaboration And Participation In Practice Presentation
Gov 2 0  Transparency  Collaboration  And Participation In Practice PresentationGov 2 0  Transparency  Collaboration  And Participation In Practice Presentation
Gov 2 0 Transparency Collaboration And Participation In Practice Presentationrailsconf
 
Crate Packaging Standalone Ruby Applications
Crate  Packaging Standalone Ruby ApplicationsCrate  Packaging Standalone Ruby Applications
Crate Packaging Standalone Ruby Applicationsrailsconf
 
Develop With Pleasure Deploy With Fun Glass Fish And Net Beans For A Better...
Develop With Pleasure  Deploy With Fun  Glass Fish And Net Beans For A Better...Develop With Pleasure  Deploy With Fun  Glass Fish And Net Beans For A Better...
Develop With Pleasure Deploy With Fun Glass Fish And Net Beans For A Better...railsconf
 
Building A Mini Google High Performance Computing In Ruby
Building A Mini Google  High Performance Computing In RubyBuilding A Mini Google  High Performance Computing In Ruby
Building A Mini Google High Performance Computing In Rubyrailsconf
 
A Z Introduction To Ruby On Rails
A Z Introduction To Ruby On RailsA Z Introduction To Ruby On Rails
A Z Introduction To Ruby On Railsrailsconf
 
The Even Darker Art Of Rails Engines Presentation
The Even Darker Art Of Rails Engines PresentationThe Even Darker Art Of Rails Engines Presentation
The Even Darker Art Of Rails Engines Presentationrailsconf
 
Below And Beneath Tdd Test Last Development And Other Real World Test Patter...
Below And Beneath Tdd  Test Last Development And Other Real World Test Patter...Below And Beneath Tdd  Test Last Development And Other Real World Test Patter...
Below And Beneath Tdd Test Last Development And Other Real World Test Patter...railsconf
 

More from railsconf (13)

Smacking Git Around Advanced Git Tricks
Smacking Git Around   Advanced Git TricksSmacking Git Around   Advanced Git Tricks
Smacking Git Around Advanced Git Tricks
 
Running The Show Configuration Management With Chef Presentation
Running The Show  Configuration Management With Chef PresentationRunning The Show  Configuration Management With Chef Presentation
Running The Show Configuration Management With Chef Presentation
 
Sd208 Ds%2 C0
Sd208 Ds%2 C0Sd208 Ds%2 C0
Sd208 Ds%2 C0
 
Rails 3 And The Real Secret To High Productivity Presentation
Rails 3 And The Real Secret To High Productivity PresentationRails 3 And The Real Secret To High Productivity Presentation
Rails 3 And The Real Secret To High Productivity Presentation
 
Quality Code With Cucumber Presentation
Quality Code With Cucumber PresentationQuality Code With Cucumber Presentation
Quality Code With Cucumber Presentation
 
J Ruby On Rails Presentation
J Ruby On Rails PresentationJ Ruby On Rails Presentation
J Ruby On Rails Presentation
 
Gov 2 0 Transparency Collaboration And Participation In Practice Presentation
Gov 2 0  Transparency  Collaboration  And Participation In Practice PresentationGov 2 0  Transparency  Collaboration  And Participation In Practice Presentation
Gov 2 0 Transparency Collaboration And Participation In Practice Presentation
 
Crate Packaging Standalone Ruby Applications
Crate  Packaging Standalone Ruby ApplicationsCrate  Packaging Standalone Ruby Applications
Crate Packaging Standalone Ruby Applications
 
Develop With Pleasure Deploy With Fun Glass Fish And Net Beans For A Better...
Develop With Pleasure  Deploy With Fun  Glass Fish And Net Beans For A Better...Develop With Pleasure  Deploy With Fun  Glass Fish And Net Beans For A Better...
Develop With Pleasure Deploy With Fun Glass Fish And Net Beans For A Better...
 
Building A Mini Google High Performance Computing In Ruby
Building A Mini Google  High Performance Computing In RubyBuilding A Mini Google  High Performance Computing In Ruby
Building A Mini Google High Performance Computing In Ruby
 
A Z Introduction To Ruby On Rails
A Z Introduction To Ruby On RailsA Z Introduction To Ruby On Rails
A Z Introduction To Ruby On Rails
 
The Even Darker Art Of Rails Engines Presentation
The Even Darker Art Of Rails Engines PresentationThe Even Darker Art Of Rails Engines Presentation
The Even Darker Art Of Rails Engines Presentation
 
Below And Beneath Tdd Test Last Development And Other Real World Test Patter...
Below And Beneath Tdd  Test Last Development And Other Real World Test Patter...Below And Beneath Tdd  Test Last Development And Other Real World Test Patter...
Below And Beneath Tdd Test Last Development And Other Real World Test Patter...
 

Recently uploaded

APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 

Recently uploaded (20)

APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 

Rails Is From Mars Ruby Is From Venus Presentation 1

  • 1. RAILS IS FROM MARS RUBY IS FROM VENUS Relationship Advice For Rails Developers
  • 2. WHO AM I? • My name is Rein Henrichs. • That’s pronounced like “rain”. • But spelled differently. •I work at •I blog at reinh.com •I twitter @reinh •I like candlelit dinners and long walks on the beach.
  • 3. insert logo here :( YOU KNOW RAILS
  • 4. BUT DO YOU KNOW RUBY?
  • 5. How many people here use Rails?
  • 6. How many of you think you know Ruby as well as you know Rails?
  • 7. How many of you have contributed to an open-source Ruby project?
  • 8. How many of you have written your own gem?
  • 9. How many of you would be comfortable writing an HTTP client library in Ruby?
  • 10. How many of you could write your own web framework?
  • 11. WHY SHOULD I LEARN RUBY? • It’s easy. • It’s fun. • It will make you better at Rails. • It will make you a better person.
  • 12. HOW DO I LEARN RUBY? Some resources
  • 14. WHY’S POIGNANT GUIDE It has cartoon foxes. Foxen? It has cartoon foxen.
  • 15. PROGRAMMING RUBY a.k.a. The Pickaxe
  • 16. MR. NEIGHBORLY’S HUMBLE LITTLE RUBY BOOK Pragmatically chunky bacon
  • 17. Not so free stuff (but still really good)
  • 18. RUBY IN A NUTSHELL Come on. Matz wrote it.
  • 19. RUBY IN PRACTICE Look at that funny looking guy on the cover. At least it’s not a nasty monkey. Sorry, O’Reilly
  • 20. THE RUBY WAY
  • 21. RUBY FOR RAILS
  • 23. RAILS HAS OPINIONS And Ruby Likes To Talk
  • 25. Ruby is a communicative language
  • 26. Sometimes, Ruby just wants someone to listen to it.
  • 27. If you’re programming along, doing nicely, and all of a sudden your program gets balky, makes things hard for you, it’s talking. It’s telling you there is something important missing. – Kent Beck, Smalltalk Best Practice Patterns
  • 28. It is your responsibility to listen to your code and be considerate of its needs.
  • 29. Write Ruby code that communicates well but be respectful of Rails’ opinions
  • 30. Other people who use your code (including six-months-later you) will thank you.
  • 31. Ruby makes it easy to write simply, clearly and expressively
  • 32. Rails has powerful idioms and conventions
  • 33. Combining the two makes for a happy, fulfilling relationship
  • 34. RUBY LOVES YOU But Sometimes You Drive Her Crazy
  • 35. These are some of the things you do that drive Ruby crazy.
  • 37. # Bad i = 0; while i < array.size do puts array[i] i += 1 end # Better for item in array puts item end # Best array.each do |item| puts item end
  • 38. WHY? • Ruby has powerful iterators. • You don’t need to write your own. ... in ... just calls #each internally. • for
  • 39. # Bad value = value ? value : quot;defaultquot; # Better value = value || quot;defaultquot; # Best value ||= quot;defaultquot;
  • 40. WHY? • Ternaries (the ? : thing) are ugly. • Ruby has pretty assignment with operators like += and ||=
  • 41. # Bad array << 42 unless array.include?(42) array = array + [42] unless array.include?(42) # Better array = array | [42] # Best array |= [42]
  • 42. WHY? • Sometimes it just helps to know what set union is.
  • 43. # Bad if value != nil && value != false # Good if value
  • 44. WHY? • Ruby has a sane notion of truthiness
  • 45. # Bad if value == 1 || value == 12 || value == 42 # Good if [1,12,42].include? value
  • 46. WHY? • Brevity is not the goal • Readability is the goal • But if it is more readable and also shorter, go for it.
  • 47. # Bad def request begin perform_request rescue RequestError => e log_error e end end # Good def request perform_request rescue RequestError => e log_error e end
  • 48. WHY? • Method definitions are an implied begin block.
  • 50. WHY? • Ruby does not not like clarity. • What you lose in readability you gain in nothing.
  • 52. WHY? • Naming things is important. • Base? What does that even mean? • Sorry Rails, you got this one wrong. Better luck next time.
  • 53. # Bad class PostsController < ApplicationController def recent Post.find :all, :conditions => ['posts.created_at > ?', 1.week.ago] end end
  • 54. # Good class PostsController < ApplicationController def recent Post.within 1.week end end
  • 55. class Post < ActiveRecord::Base named_scope :within, lambda {|seconds| :conditions => ['posts.created_at > ?', seconds.ago]} end
  • 56. WHY? • Make your code more expressive • And more intention revealing. • In other words, say what you mean to say.
  • 57. url_for(:blog, :posts, @post.id, :comments, :replies => true) # => http://example.com/blog/posts/19/comments?replies=true
  • 58. # Bad def url_for(*args) root + args.map{|arg| parse_arg(arg)}.join('/'). gsub('/?', '?') end def parse_arg(arg) case arg when Array: arg.join('/') when Hash ret = [] each{|k,v| ret << quot;#{k}=#{v}quot;} ret = ret.join('&') '?' + ret else: arg.to_s end end
  • 59. # Good def url_for(*args) root + args.to_params end
  • 60. class Array def to_params map{|a| a.to_params}.join('/'). gsub('/?', '?') end end
  • 61. # Array %w(foo bar bazz).to_params # quot;/foo/bar/bazzquot; # Hash {:foo => :bar}.to_params # quot;?foo=barquot;
  • 62. WHY? • Ruby uses coercion in many places • 1.to_s • (1..10).to_a • Writingyour own coercion method can help you use Ruby’s ducktyping. • Separation of concerns.
  • 63. RAILS PERFORMANCE Insert your “scaling” and “premature optimization” jokes here.
  • 64. Yes, I went there.
  • 65. Slow is only meaningful in comparison.
  • 66. Ruby is slow? Compared to what?
  • 68. Are your views slow?
  • 69. Is your app server slow?
  • 70. Are you using HTTP via carrier pigeon?
  • 71. If you don’t know where the slow is, you’re not ready to optimize.
  • 72. Don’t optimize prematurely, but don’t pessimize either.
  • 73. Don’t write code you know will never, ever be fast.
  • 74. # Really Bad (Optimally Pessimum) class Ballot < ActiveRecord::Base def <=>(other) votes.count <=> other.votes.count end end # Good (Potentially Optimum) class Ballot < ActiveRecord::Base # With a counter_cache on votes default_scope :order => :votes_count end
  • 75. IN OTHER WORDS • Don’t worry about speed until you know where the slow is. • Worry about writing simply and expressively. • Well written code is easy to optimize for performance later. • Don’t write something you know will never, ever be fast.
  • 76. IN CONCLUSION • Ruby is fun and easy (and friendly!). • Ruby will make you happy. • Be more thoughtful in the way you treat Ruby. • The more Ruby you know, the better you can become at Rails. • If you love Rails, you should love Ruby too. • Also, don’t be premature. No one likes that.
  • 77. WHO AM I? • My name is Rein Henrichs. • That’s pronounced like “rain”. • But spelled differently. •I work at •I blog at reinh.com •I twitter @reinh •I like candlelit dinners and long walks on the beach.