SlideShare a Scribd company logo
1 of 67
Keeping
  Ruby
Reasonable
Hi there!
Allow me to introduce
       myself...
My name is
Joshua Ballanco
    @manhattanmetric
 https://github.com/jballanc
I work for
I work for
I am also a MacRuby
   team member
 (and I tend to talk about MacRuby a lot)
Keeping
  Ruby
Reasonable
rea· son· a· ble
adj.
/ˈrēz(ə)nəbəl/
• Based on good sense
rea· son· a· ble
adj.
/ˈrēz(ə)nəbəl/
• Able to be reasoned
 about
A Story
Ruby Reasoner wanted to write a class:
Peter Pythonista wanted to “help”:
So Mr. Reasoner ran
    the code...
What is going on?!?
What is going on?!?
Ruby,
we need to talk...
1+1
What does it mean?!?
1+1
    What does it mean?!?
• Math equation?
1+1
    What does it mean?!?
• Math equation?
• Program?
foo = Bar.new(baz.qux)
   What does it mean?!?
• Math equation?
• Program?
foo = Bar.new(baz.qux)
   What does it mean?!?
• Math equation?
• Program?
• What language?
foo = Bar.new(baz.qux)
   What does it mean?!?
• Math equation?
• Program?
• What language?
• Tokens? Symbols?
foo = Bar.new(baz.qux)
   What does it mean?!?
• Math equation?
• Program?
• What language?
• Tokens? Symbols?
• Function bindings? Semantics? Value
  transformations???
Mind
    Your
Environment!
Can I get a definition?
Can I get a definition?
      Binding
Can I get a definition?
                 Binding

   Bindings
            {
(Environment)
Can I get a definition?
                 Binding

   Bindings
            {
(Environment)              Closure
Can I get a definition?
                 Binding

   Bindings
            {
(Environment)                Closure




                           First-class Environment
Motivation
Motivation
I really liked first-class environments when I was first
exposed to them...


  ...At this point I believe that first-class environments
            are useless at best, and dangerous at worst.
Design of First-Class Environments

 Four questions to ask when designing a first-
     class environment implementation...
Design of First-Class Environments

Should you be able to extract an environment
from any closure?
1. Yes
2. No
Design of First-Class Environments

Should you be able to extract an environment
from any closure?
1. Yes     Ruby’s Choice
2. No
Design of First-Class Environments

Should all bindings in the lexical scope of the
closure be captured by the environment?
1. All
2. Only those used
3. Only those explicitly specified
Design of First-Class Environments

Should all bindings in the lexical scope of the
closure be captured by the environment?
1. All     Ruby’s Choice
2. Only those used
3. Only those explicitly specified
Design of First-Class Environments

Should bindings be live in the environment?
1.   All bindings are live and mutable
2.   Bindings are live, but read-only
3.   Bindings are a snapshot in time
4.   User specifies state of each binding
Design of First-Class Environments

Should bindings be live in the environment?
1. All bindings are live and mutable     Ruby’s
2. Bindings are live, but read-only     Choice
3. Bindings are a snapshot in time
4. User specifies state of each binding
Design of First-Class Environments

What happens if you define a new binding
using the environment?
1. New binding shadows old binding
2. Environment is cloned containing new
   binding
3. Defining new bindings is not allowed
Design of First-Class Environments

What happens if you define a new binding
using the environment?
                                          Ruby’s
1. New binding shadows old binding
                                          Choice
2. Environment is cloned containing new
   binding
3. Defining new bindings is not allowed
Design of First-Class Environments

      “When someone suggests ‘first-class
environments’, I assume they want options 1, 1,
  1, and 1 ... In this variation, though, the user
     simply cannot reason about his code.”
Design of First-Class Environments

      “When someone suggests ‘first-class
environments’, I assume they want options 1, 1,
  1, and 1 ... In this variation, though, the user
     simply cannot reason about his code.”

     Ruby chooses options 1, 1, 1, and 1 !
What’s a language to do?
    R6RS Scheme (http://www.r6rs.org/)




• Bindings in the environment must be
  specified explicitly using a library reference
• New bindings cannot be created in the
  environment
What’s a language to do?
Objective-C doesn’t have first-class environments, but...
What’s a language to do?
Objective-C doesn’t have first-class environments, but...




                      Retained, read-only binding
What’s a language to do?
Objective-C doesn’t have first-class environments, but...




                      Retained, read-only binding



                               Live binding
What’s a language to do?
Objective-C doesn’t have first-class environments, but...

                                      Collected!


                      Retained, read-only binding



                               Live binding
I am but a humble Ruby programmer

• How many times have you done this?
I am but a humble Ruby programmer

• How many times have you done this?




• ...and thought you were safe?
I am but a humble Ruby programmer

  • How many times have you done this?



  • And later needed to do this?
I am but a humble Ruby programmer

  • How many times have you done this?



  • And later needed to do this?
I am but a humble Ruby programmer

  • How many times have you done this?



  • And later needed to do this?

  • Is that even reasonable?
First-class Environments are hard...let’s play
                       a game!

            Let’s play: Capture the Flag

Rules:
• You must provide a class
• The class must contain a method named “flag”
• The class must contain a class constant named “Base”
• The “Base” must be a proc object
• You may only define one class
• You may not require or load other source files in
  your class
The only winning move is not to play...
Blue Team, GO!
Red Team, GO!
Red Team
 WINS!
 ...but why?
Send in a spy...
What did we learn?
• Ruby’s first-class environments make it
  difficult to reason about code (and
  therefore difficult to optimize)
• Ruby does have a restricted version of a
  first-class environment in the Method class
• Re-thinking and formalizing first-class
  environment semantics could make Ruby
  faster, unbound methods more useful, and
  Ruby more reasonable in general
References
• https://github.com/jballanc/reasonable_ruby
• http://funcall.blogspot.com/
• http://pinboard.in/u:jballanc/
  t:Keeping_Ruby_Reasonable/



           Questions?

More Related Content

Similar to Keeping ruby reasonable

Learn Ruby 2011 - Session 1
Learn Ruby 2011 - Session 1Learn Ruby 2011 - Session 1
Learn Ruby 2011 - Session 1James Thompson
 
Day 1 - Intro to Ruby
Day 1 - Intro to RubyDay 1 - Intro to Ruby
Day 1 - Intro to RubyBarry Jones
 
C# .NET - Um overview da linguagem
C# .NET - Um overview da linguagem C# .NET - Um overview da linguagem
C# .NET - Um overview da linguagem Claudson Oliveira
 
Ruby object model
Ruby object modelRuby object model
Ruby object modelmbeizer
 
Ruby for PHP developers
Ruby for PHP developersRuby for PHP developers
Ruby for PHP developersMax Titov
 
Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Henry S
 
Go for Rubyists. August 2018. RUG-B Meetup
Go for Rubyists. August 2018. RUG-B MeetupGo for Rubyists. August 2018. RUG-B Meetup
Go for Rubyists. August 2018. RUG-B MeetupKirill Zonov
 
Intro To Ror
Intro To RorIntro To Ror
Intro To Rormyuser
 
What can Ruby learn from Python (and vice versa)?
What can Ruby learn from Python (and vice versa)?What can Ruby learn from Python (and vice versa)?
What can Ruby learn from Python (and vice versa)?Reuven Lerner
 
Ruby for .NET developers
Ruby for .NET developersRuby for .NET developers
Ruby for .NET developersMax Titov
 
Ruby Metaprogramming - OSCON 2008
Ruby Metaprogramming - OSCON 2008Ruby Metaprogramming - OSCON 2008
Ruby Metaprogramming - OSCON 2008Brian Sam-Bodden
 
Asakusa ruby
Asakusa rubyAsakusa ruby
Asakusa rubypragdave
 
Write a better FM
Write a better FMWrite a better FM
Write a better FMRich Bowen
 
Why i love ruby than x
Why i love ruby than xWhy i love ruby than x
Why i love ruby than xSamnang Chhun
 
Ruby, the language of devops
Ruby, the language of devopsRuby, the language of devops
Ruby, the language of devopsRob Kinyon
 
Merb Camp Keynote
Merb Camp KeynoteMerb Camp Keynote
Merb Camp KeynoteYehuda Katz
 

Similar to Keeping ruby reasonable (20)

Learn Ruby 2011 - Session 1
Learn Ruby 2011 - Session 1Learn Ruby 2011 - Session 1
Learn Ruby 2011 - Session 1
 
Day 1 - Intro to Ruby
Day 1 - Intro to RubyDay 1 - Intro to Ruby
Day 1 - Intro to Ruby
 
C# .NET - Um overview da linguagem
C# .NET - Um overview da linguagem C# .NET - Um overview da linguagem
C# .NET - Um overview da linguagem
 
Ruby object model
Ruby object modelRuby object model
Ruby object model
 
Ruby for PHP developers
Ruby for PHP developersRuby for PHP developers
Ruby for PHP developers
 
Python overview
Python overviewPython overview
Python overview
 
Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1
 
Go for Rubyists. August 2018. RUG-B Meetup
Go for Rubyists. August 2018. RUG-B MeetupGo for Rubyists. August 2018. RUG-B Meetup
Go for Rubyists. August 2018. RUG-B Meetup
 
Intro To Ror
Intro To RorIntro To Ror
Intro To Ror
 
What can Ruby learn from Python (and vice versa)?
What can Ruby learn from Python (and vice versa)?What can Ruby learn from Python (and vice versa)?
What can Ruby learn from Python (and vice versa)?
 
Ruby for .NET developers
Ruby for .NET developersRuby for .NET developers
Ruby for .NET developers
 
Cucumber in Practice(en)
Cucumber in Practice(en)Cucumber in Practice(en)
Cucumber in Practice(en)
 
Ruby Metaprogramming - OSCON 2008
Ruby Metaprogramming - OSCON 2008Ruby Metaprogramming - OSCON 2008
Ruby Metaprogramming - OSCON 2008
 
Asakusa ruby
Asakusa rubyAsakusa ruby
Asakusa ruby
 
OOP vs COP
OOP vs COPOOP vs COP
OOP vs COP
 
Write a better FM
Write a better FMWrite a better FM
Write a better FM
 
Why i love ruby than x
Why i love ruby than xWhy i love ruby than x
Why i love ruby than x
 
Why Ruby?
Why Ruby? Why Ruby?
Why Ruby?
 
Ruby, the language of devops
Ruby, the language of devopsRuby, the language of devops
Ruby, the language of devops
 
Merb Camp Keynote
Merb Camp KeynoteMerb Camp Keynote
Merb Camp Keynote
 

More from Joshua Ballanco

More from Joshua Ballanco (7)

The Two Cultures of Programming
The Two Cultures of ProgrammingThe Two Cultures of Programming
The Two Cultures of Programming
 
What's Eating Ruby?
What's Eating Ruby?What's Eating Ruby?
What's Eating Ruby?
 
Community in Motion
Community in MotionCommunity in Motion
Community in Motion
 
RubyMotion: Under the Hood
RubyMotion: Under the HoodRubyMotion: Under the Hood
RubyMotion: Under the Hood
 
Getting Your Ruby EGOT
Getting Your Ruby EGOTGetting Your Ruby EGOT
Getting Your Ruby EGOT
 
Debugging RubyMotion
Debugging RubyMotionDebugging RubyMotion
Debugging RubyMotion
 
There and Back Again
There and Back AgainThere and Back Again
There and Back Again
 

Recently uploaded

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
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
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
 
"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
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
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
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
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
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 

Recently uploaded (20)

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
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
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
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
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...
 
"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...
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
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
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
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?
 
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
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 

Keeping ruby reasonable

  • 3. Allow me to introduce myself...
  • 4. My name is Joshua Ballanco @manhattanmetric https://github.com/jballanc
  • 7. I am also a MacRuby team member (and I tend to talk about MacRuby a lot)
  • 9. rea· son· a· ble adj. /ˈrēz(ə)nəbəl/ • Based on good sense
  • 10. rea· son· a· ble adj. /ˈrēz(ə)nəbəl/ • Able to be reasoned about
  • 12. Ruby Reasoner wanted to write a class:
  • 13. Peter Pythonista wanted to “help”:
  • 14. So Mr. Reasoner ran the code...
  • 15.
  • 16.
  • 17. What is going on?!?
  • 18. What is going on?!?
  • 19. Ruby, we need to talk...
  • 20. 1+1 What does it mean?!?
  • 21. 1+1 What does it mean?!? • Math equation?
  • 22. 1+1 What does it mean?!? • Math equation? • Program?
  • 23. foo = Bar.new(baz.qux) What does it mean?!? • Math equation? • Program?
  • 24. foo = Bar.new(baz.qux) What does it mean?!? • Math equation? • Program? • What language?
  • 25. foo = Bar.new(baz.qux) What does it mean?!? • Math equation? • Program? • What language? • Tokens? Symbols?
  • 26. foo = Bar.new(baz.qux) What does it mean?!? • Math equation? • Program? • What language? • Tokens? Symbols? • Function bindings? Semantics? Value transformations???
  • 27. Mind Your Environment!
  • 28. Can I get a definition?
  • 29. Can I get a definition? Binding
  • 30. Can I get a definition? Binding Bindings { (Environment)
  • 31. Can I get a definition? Binding Bindings { (Environment) Closure
  • 32. Can I get a definition? Binding Bindings { (Environment) Closure First-class Environment
  • 34. Motivation I really liked first-class environments when I was first exposed to them... ...At this point I believe that first-class environments are useless at best, and dangerous at worst.
  • 35. Design of First-Class Environments Four questions to ask when designing a first- class environment implementation...
  • 36. Design of First-Class Environments Should you be able to extract an environment from any closure? 1. Yes 2. No
  • 37. Design of First-Class Environments Should you be able to extract an environment from any closure? 1. Yes Ruby’s Choice 2. No
  • 38. Design of First-Class Environments Should all bindings in the lexical scope of the closure be captured by the environment? 1. All 2. Only those used 3. Only those explicitly specified
  • 39. Design of First-Class Environments Should all bindings in the lexical scope of the closure be captured by the environment? 1. All Ruby’s Choice 2. Only those used 3. Only those explicitly specified
  • 40. Design of First-Class Environments Should bindings be live in the environment? 1. All bindings are live and mutable 2. Bindings are live, but read-only 3. Bindings are a snapshot in time 4. User specifies state of each binding
  • 41. Design of First-Class Environments Should bindings be live in the environment? 1. All bindings are live and mutable Ruby’s 2. Bindings are live, but read-only Choice 3. Bindings are a snapshot in time 4. User specifies state of each binding
  • 42. Design of First-Class Environments What happens if you define a new binding using the environment? 1. New binding shadows old binding 2. Environment is cloned containing new binding 3. Defining new bindings is not allowed
  • 43. Design of First-Class Environments What happens if you define a new binding using the environment? Ruby’s 1. New binding shadows old binding Choice 2. Environment is cloned containing new binding 3. Defining new bindings is not allowed
  • 44. Design of First-Class Environments “When someone suggests ‘first-class environments’, I assume they want options 1, 1, 1, and 1 ... In this variation, though, the user simply cannot reason about his code.”
  • 45. Design of First-Class Environments “When someone suggests ‘first-class environments’, I assume they want options 1, 1, 1, and 1 ... In this variation, though, the user simply cannot reason about his code.” Ruby chooses options 1, 1, 1, and 1 !
  • 46. What’s a language to do? R6RS Scheme (http://www.r6rs.org/) • Bindings in the environment must be specified explicitly using a library reference • New bindings cannot be created in the environment
  • 47. What’s a language to do? Objective-C doesn’t have first-class environments, but...
  • 48. What’s a language to do? Objective-C doesn’t have first-class environments, but... Retained, read-only binding
  • 49. What’s a language to do? Objective-C doesn’t have first-class environments, but... Retained, read-only binding Live binding
  • 50. What’s a language to do? Objective-C doesn’t have first-class environments, but... Collected! Retained, read-only binding Live binding
  • 51. I am but a humble Ruby programmer • How many times have you done this?
  • 52. I am but a humble Ruby programmer • How many times have you done this? • ...and thought you were safe?
  • 53. I am but a humble Ruby programmer • How many times have you done this? • And later needed to do this?
  • 54. I am but a humble Ruby programmer • How many times have you done this? • And later needed to do this?
  • 55. I am but a humble Ruby programmer • How many times have you done this? • And later needed to do this? • Is that even reasonable?
  • 56. First-class Environments are hard...let’s play a game! Let’s play: Capture the Flag Rules: • You must provide a class • The class must contain a method named “flag” • The class must contain a class constant named “Base” • The “Base” must be a proc object • You may only define one class • You may not require or load other source files in your class
  • 57. The only winning move is not to play...
  • 59.
  • 61.
  • 62. Red Team WINS! ...but why?
  • 63. Send in a spy...
  • 64.
  • 65.
  • 66. What did we learn? • Ruby’s first-class environments make it difficult to reason about code (and therefore difficult to optimize) • Ruby does have a restricted version of a first-class environment in the Method class • Re-thinking and formalizing first-class environment semantics could make Ruby faster, unbound methods more useful, and Ruby more reasonable in general
  • 67. References • https://github.com/jballanc/reasonable_ruby • http://funcall.blogspot.com/ • http://pinboard.in/u:jballanc/ t:Keeping_Ruby_Reasonable/ Questions?

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n