Your SlideShare is downloading. ×
Keeping  RubyReasonable
Hi there!
Allow me to introduce       myself...
My name isJoshua 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  RubyReasonable
rea· son· a· bleadj./ˈrēz(ə)nəbəl/• Based on good sense
rea· son· a· bleadj./ˈ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?!?
1+1What 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 bindin...
Mind    YourEnvironment!
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                ...
Motivation
MotivationI really liked first-class environments when I was firstexposed to them...  ...At this point I believe that first-c...
Design of First-Class Environments Four questions to ask when designing a first-     class environment implementation...
Design of First-Class EnvironmentsShould you be able to extract an environmentfrom any closure?1. Yes2. No
Design of First-Class EnvironmentsShould you be able to extract an environmentfrom any closure?1. Yes     Ruby’s Choice2. No
Design of First-Class EnvironmentsShould all bindings in the lexical scope of theclosure be captured by the environment?1....
Design of First-Class EnvironmentsShould all bindings in the lexical scope of theclosure be captured by the environment?1....
Design of First-Class EnvironmentsShould bindings be live in the environment?1.   All bindings are live and mutable2.   Bi...
Design of First-Class EnvironmentsShould bindings be live in the environment?1. All bindings are live and mutable     Ruby...
Design of First-Class EnvironmentsWhat happens if you define a new bindingusing the environment?1. New binding shadows old ...
Design of First-Class EnvironmentsWhat happens if you define a new bindingusing the environment?                           ...
Design of First-Class Environments      “When someone suggests ‘first-classenvironments’, I assume they want options 1, 1, ...
Design of First-Class Environments      “When someone suggests ‘first-classenvironments’, I assume they want options 1, 1, ...
What’s a language to do?    R6RS Scheme (http://www.r6rs.org/)• Bindings in the environment must be  specified explicitly u...
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 ...
What’s a language to do?Objective-C doesn’t have first-class environments, but...                      Retained, read-only ...
What’s a language to do?Objective-C doesn’t have first-class environments, but...                                      Coll...
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 re...
First-class Environments are hard...let’s play                       a game!            Let’s play: Capture the FlagRules:...
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 opti...
Keeping ruby reasonable
Keeping ruby reasonable
Keeping ruby reasonable
Keeping ruby reasonable
Keeping ruby reasonable
Keeping ruby reasonable
Keeping ruby reasonable
Keeping ruby reasonable
Upcoming SlideShare
Loading in...5
×

Keeping ruby reasonable

5,172

Published on

These are the slides from my RubyConf 2011 talk: "Keeping Ruby Reasonable". In this talk, I covered how first-class environments are implemented in Ruby, and why that poses a problem for Ruby programmers.

Published in: Technology, Education
0 Comments
7 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
5,172
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
7
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Transcript of "Keeping ruby reasonable"

    1. 1. Keeping RubyReasonable
    2. 2. Hi there!
    3. 3. Allow me to introduce myself...
    4. 4. My name isJoshua Ballanco @manhattanmetric https://github.com/jballanc
    5. 5. I work for
    6. 6. I work for
    7. 7. I am also a MacRuby team member (and I tend to talk about MacRuby a lot)
    8. 8. Keeping RubyReasonable
    9. 9. rea· son· a· bleadj./ˈrēz(ə)nəbəl/• Based on good sense
    10. 10. rea· son· a· bleadj./ˈrēz(ə)nəbəl/• Able to be reasoned about
    11. 11. A Story
    12. 12. Ruby Reasoner wanted to write a class:
    13. 13. Peter Pythonista wanted to “help”:
    14. 14. So Mr. Reasoner ran the code...
    15. 15. What is going on?!?
    16. 16. What is going on?!?
    17. 17. Ruby,we need to talk...
    18. 18. 1+1What does it mean?!?
    19. 19. 1+1 What does it mean?!?• Math equation?
    20. 20. 1+1 What does it mean?!?• Math equation?• Program?
    21. 21. foo = Bar.new(baz.qux) What does it mean?!?• Math equation?• Program?
    22. 22. foo = Bar.new(baz.qux) What does it mean?!?• Math equation?• Program?• What language?
    23. 23. foo = Bar.new(baz.qux) What does it mean?!?• Math equation?• Program?• What language?• Tokens? Symbols?
    24. 24. foo = Bar.new(baz.qux) What does it mean?!?• Math equation?• Program?• What language?• Tokens? Symbols?• Function bindings? Semantics? Value transformations???
    25. 25. Mind YourEnvironment!
    26. 26. Can I get a definition?
    27. 27. Can I get a definition? Binding
    28. 28. Can I get a definition? Binding Bindings {(Environment)
    29. 29. Can I get a definition? Binding Bindings {(Environment) Closure
    30. 30. Can I get a definition? Binding Bindings {(Environment) Closure First-class Environment
    31. 31. Motivation
    32. 32. MotivationI really liked first-class environments when I was firstexposed to them... ...At this point I believe that first-class environments are useless at best, and dangerous at worst.
    33. 33. Design of First-Class Environments Four questions to ask when designing a first- class environment implementation...
    34. 34. Design of First-Class EnvironmentsShould you be able to extract an environmentfrom any closure?1. Yes2. No
    35. 35. Design of First-Class EnvironmentsShould you be able to extract an environmentfrom any closure?1. Yes Ruby’s Choice2. No
    36. 36. Design of First-Class EnvironmentsShould all bindings in the lexical scope of theclosure be captured by the environment?1. All2. Only those used3. Only those explicitly specified
    37. 37. Design of First-Class EnvironmentsShould all bindings in the lexical scope of theclosure be captured by the environment?1. All Ruby’s Choice2. Only those used3. Only those explicitly specified
    38. 38. Design of First-Class EnvironmentsShould bindings be live in the environment?1. All bindings are live and mutable2. Bindings are live, but read-only3. Bindings are a snapshot in time4. User specifies state of each binding
    39. 39. Design of First-Class EnvironmentsShould bindings be live in the environment?1. All bindings are live and mutable Ruby’s2. Bindings are live, but read-only Choice3. Bindings are a snapshot in time4. User specifies state of each binding
    40. 40. Design of First-Class EnvironmentsWhat happens if you define a new bindingusing the environment?1. New binding shadows old binding2. Environment is cloned containing new binding3. Defining new bindings is not allowed
    41. 41. Design of First-Class EnvironmentsWhat happens if you define a new bindingusing the environment? Ruby’s1. New binding shadows old binding Choice2. Environment is cloned containing new binding3. Defining new bindings is not allowed
    42. 42. Design of First-Class Environments “When someone suggests ‘first-classenvironments’, I assume they want options 1, 1, 1, and 1 ... In this variation, though, the user simply cannot reason about his code.”
    43. 43. Design of First-Class Environments “When someone suggests ‘first-classenvironments’, 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 !
    44. 44. 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
    45. 45. What’s a language to do?Objective-C doesn’t have first-class environments, but...
    46. 46. What’s a language to do?Objective-C doesn’t have first-class environments, but... Retained, read-only binding
    47. 47. What’s a language to do?Objective-C doesn’t have first-class environments, but... Retained, read-only binding Live binding
    48. 48. What’s a language to do?Objective-C doesn’t have first-class environments, but... Collected! Retained, read-only binding Live binding
    49. 49. I am but a humble Ruby programmer• How many times have you done this?
    50. 50. I am but a humble Ruby programmer• How many times have you done this?• ...and thought you were safe?
    51. 51. I am but a humble Ruby programmer • How many times have you done this? • And later needed to do this?
    52. 52. I am but a humble Ruby programmer • How many times have you done this? • And later needed to do this?
    53. 53. I am but a humble Ruby programmer • How many times have you done this? • And later needed to do this? • Is that even reasonable?
    54. 54. First-class Environments are hard...let’s play a game! Let’s play: Capture the FlagRules:• 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
    55. 55. The only winning move is not to play...
    56. 56. Blue Team, GO!
    57. 57. Red Team, GO!
    58. 58. Red Team WINS! ...but why?
    59. 59. Send in a spy...
    60. 60. 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
    61. 61. References• https://github.com/jballanc/reasonable_ruby• http://funcall.blogspot.com/• http://pinboard.in/u:jballanc/ t:Keeping_Ruby_Reasonable/ Questions?

    ×