Successfully reported this slideshow.

Keeping ruby reasonable

7

Share

Keeping
  Ruby
Reasonable
Hi there!
Allow me to introduce
       myself...

YouTube videos are no longer supported on SlideShare

View original on YouTube

YouTube videos are no longer supported on SlideShare

View original on YouTube

YouTube videos are no longer supported on SlideShare

View original on YouTube

YouTube videos are no longer supported on SlideShare

View original on YouTube

Upcoming SlideShare
Ruby Class 1
Ruby Class 1
Loading in …3
×
1 of 71
1 of 71

Keeping ruby reasonable

7

Share

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.

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.

More Related Content

Related Books

Free with a 14 day trial from Scribd

See all

Keeping ruby reasonable

  1. Keeping Ruby Reasonable
  2. Hi there!
  3. Allow me to introduce myself...
  4. My name is Joshua 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 Ruby Reasonable
  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
  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+1 What 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 Your Environment!
  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. 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.
  33. Design of First-Class Environments Four questions to ask when designing a first- class environment implementation...
  34. Design of First-Class Environments Should you be able to extract an environment from any closure? 1. Yes 2. No
  35. Design of First-Class Environments Should you be able to extract an environment from any closure? 1. Yes Ruby’s Choice 2. No
  36. 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
  37. 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
  38. 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
  39. 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
  40. 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
  41. 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
  42. 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.”
  43. 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 !
  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 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
  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?

Editor's Notes

  • \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
  • ×