Your SlideShare is downloading. ×
  • Like
  • Save
Keeping ruby reasonable
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Keeping ruby reasonable

  • 5,129 views
Published

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 …

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
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
5,129
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
0
Likes
7

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    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

  • 1. Keeping RubyReasonable
  • 2. Hi there!
  • 3. Allow me to introduce myself...
  • 4. My name isJoshua Ballanco @manhattanmetric https://github.com/jballanc
  • 5. I work for
  • 6. I work for
  • 7. I am also a MacRuby team member (and I tend to talk about MacRuby a lot)
  • 8. Keeping RubyReasonable
  • 9. rea· son· a· bleadj./ˈrēz(ə)nəbəl/• Based on good sense
  • 10. rea· son· a· bleadj./ˈrēz(ə)nəbəl/• Able to be reasoned about
  • 11. A Story
  • 12. Ruby Reasoner wanted to write a class:
  • 13. Peter Pythonista wanted to “help”:
  • 14. So Mr. Reasoner ran the code...
  • 15. What is going on?!?
  • 16. What is going on?!?
  • 17. Ruby,we need to talk...
  • 18. 1+1What does it mean?!?
  • 19. 1+1 What does it mean?!?• Math equation?
  • 20. 1+1 What does it mean?!?• Math equation?• Program?
  • 21. foo = Bar.new(baz.qux) What does it mean?!?• Math equation?• Program?
  • 22. foo = Bar.new(baz.qux) What does it mean?!?• Math equation?• Program?• What language?
  • 23. foo = Bar.new(baz.qux) What does it mean?!?• Math equation?• Program?• What language?• Tokens? Symbols?
  • 24. foo = Bar.new(baz.qux) What does it mean?!?• Math equation?• Program?• What language?• Tokens? Symbols?• Function bindings? Semantics? Value transformations???
  • 25. Mind YourEnvironment!
  • 26. Can I get a definition?
  • 27. Can I get a definition? Binding
  • 28. Can I get a definition? Binding Bindings {(Environment)
  • 29. Can I get a definition? Binding Bindings {(Environment) Closure
  • 30. Can I get a definition? Binding Bindings {(Environment) Closure First-class Environment
  • 31. Motivation
  • 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. Design of First-Class Environments Four questions to ask when designing a first- class environment implementation...
  • 34. Design of First-Class EnvironmentsShould you be able to extract an environmentfrom any closure?1. Yes2. No
  • 35. Design of First-Class EnvironmentsShould you be able to extract an environmentfrom any closure?1. Yes Ruby’s Choice2. No
  • 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. 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. 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. 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. 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. 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. 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. 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. 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. What’s a language to do?Objective-C doesn’t have first-class environments, but...
  • 46. What’s a language to do?Objective-C doesn’t have first-class environments, but... Retained, read-only binding
  • 47. What’s a language to do?Objective-C doesn’t have first-class environments, but... Retained, read-only binding Live binding
  • 48. What’s a language to do?Objective-C doesn’t have first-class environments, but... Collected! Retained, read-only binding Live binding
  • 49. I am but a humble Ruby programmer• How many times have you done this?
  • 50. I am but a humble Ruby programmer• How many times have you done this?• ...and thought you were safe?
  • 51. I am but a humble Ruby programmer • How many times have you done this? • And later needed to do this?
  • 52. I am but a humble Ruby programmer • How many times have you done this? • And later needed to do this?
  • 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. 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. The only winning move is not to play...
  • 56. Blue Team, GO!
  • 57. Red Team, GO!
  • 58. Red Team WINS! ...but why?
  • 59. Send in a spy...
  • 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. References• https://github.com/jballanc/reasonable_ruby• http://funcall.blogspot.com/• http://pinboard.in/u:jballanc/ t:Keeping_Ruby_Reasonable/ Questions?