Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Sugar-Free Ruby

Sugar-Free Ruby

Ruby has a lot of syntax to come to terms with. In an effort to reduce learning overhead we often restrict what we teach by avoiding serious coverage of objects in early lessons. Yet objects are what make Ruby great. Rather than sacrifice Object Oriented Mechanics, Sugar-free ruby uses a minimum of syntactic sugar to reinforce the message-passing objective semantics of Ruby until the pupil understands and then can assimilate new syntactic elements with greater ease. This talk explores the advantages and pitfalls of the technique as well as other ways to teach Ruby.

Steven! Ragnarök

September 14, 2012
Tweet

More Decks by Steven! Ragnarök

Other Decks in Programming

Transcript

  1. Who is this guy? Steven! Ragnarök contact = { "GitHub"

    => "nuclearsandwich", "Freenode" => "nuclearsandwich", "Email" => "[email protected]", "WWW" => "www.nuclearsandwich.com", "Twitter" => "@nuclearsandwich" } ''That guy with all the opinions''
  2. Why is teaching so damn hard? • It's hard to

    remember learning to program
  3. Why is teaching so damn hard? • It's hard to

    remember learning to program • It's hard to share knowledge instead of guard it
  4. Why is teaching so damn hard? In short: it takes

    a lot of self reflection to teach well.
  5. RailsBridge: Workshops for Women • Install all the things the

    night before • One full day • Focus on Ruby, Rails, or split based on experience
  6. Why do you want to learn Ruby? • I hate

    my job and hear programmers make bank
  7. Why do you want to learn Ruby? • I hate

    my job and hear programmers make bank • I know how to program but not Ruby
  8. Why do you want to learn Ruby? • I hate

    my job and hear programmers make bank • I know how to program but not Ruby • I'm curious about programming
  9. Numbers 5 + 5 #=> 10 9 / 2 #=>

    4 9.0 / 2 #=> 4.5
  10. Boolean Values true #=> true false #=> false 20 <

    100 #=> true true and false #=> false true or false #=> true
  11. Arrays and Hashes [ 1, 2, 3.0, "four" ] {

    :name => "Steven!", :age => 24, :species => "human" }
  12. Variable Access # ten years from now my_age + 10

    #=> 34 # I hashify myself { :name => my_name, :age => my_age } #=> {:name => "Steven!", # :age => 24}
  13. But Steven!, If we try to teach all of that

    and Objects, their heads will explode!
  14. Everything is an Object 5 #=> 5 42.0 #=> 42.0

    "Hello!" #=> "Hello!" [1, 2, 3] #=> [1, 2, 3]
  15. Objects Have (a) Class 5.send :class #=> Fixnum 4.0.send :class

    #=> Float ["he's", "crazy?"].send :class #=> Array
  16. Feature Request: Color pen.ink_color = "Blue" #=> NoMethodError: undefined #

    method `ink_color=' for # A trusty pen:Object def pen.ink_color= color @ink_color = color end #=> nil
  17. Showing Our Colors def pen.to_s "A trusty #{@ink_color} pen" end

    pen.ink_color = "purple" #=> "purple" pen #=> "A trusty purple pen"
  18. Implicit Receivers def pen.sparkly_write thing write "*;. #{thing} *;.*" end

    pen.sparkly_write pen *;. A trusty purple pen *;.*
  19. Conditionals Revisited def pen.html_write thing write if @ink_color "<p style=\"color:

    \ #{@ink_color};\"> #{thing} </p>" else "<p>#{thing}</p>" end end
  20. Time to get classy… Scribe = Class.new do def initialize

    pen @pen = pen @items = Array.new end def note item @items.<< item end # to be continued
  21. …you blockhead # in the Scribe class body def write_everything

    @items.each do |item| @pen.write item end end end #=> Scribe
  22. Hiring a new scribe mielot = Scribe.new pen #=> #<Scribe:0x007fe57b086228

    # @pen=A trusty purple pen> mielot.note "Time: #{Time.now}" mielot.note "This demo is over" mielot.write_everything Time: 2012-09-14 11:43:05 -0700 This demo is over
  23. Why is this better? The object metaphor provides a context

    for everything else we learn about Ruby
  24. Why is this better? We don't bombard them with new

    concepts until just before their use
  25. Why is this better? With a thorough understanding of semantics,

    new things (like syntactic sugar) are more readily digestible