• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Keeping ruby reasonable
 

Keeping ruby reasonable

on

  • 5,357 views

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.

Statistics

Views

Total Views
5,357
Views on SlideShare
5,311
Embed Views
46

Actions

Likes
7
Downloads
0
Comments
0

8 Embeds 46

http://paper.li 24
http://coderwall.com 13
http://www.hanrss.com 4
http://us-w1.rockmelt.com 1
http://us-w1.rockmelt.com 1
http://www.onlydoo.com 1
http://www.onlydoo.com 1
http://a0.twimg.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

CC Attribution-NonCommercial LicenseCC Attribution-NonCommercial License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \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

Keeping ruby reasonable Keeping ruby reasonable Presentation Transcript

  • 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?!?
  • Ruby,we need to talk...
  • 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 bindings? Semantics? Value transformations???
  • 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 First-class Environment
  • Motivation
  • 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.
  • 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. All2. Only those used3. Only those explicitly specified
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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.”
  • 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 !
  • 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 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
  • 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?