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

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 

Recently uploaded (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

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