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

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
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
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 

Recently uploaded (20)

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
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)
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 

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