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

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
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
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
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
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
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
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 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