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

Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
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
 
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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
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
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
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
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
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
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
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
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 

Recently uploaded (20)

Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
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
 
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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
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
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
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
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
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
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
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
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 

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