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.

4698d387cdde58a95c8dc7f8d198cb48?s=128

Steven! Ragnarök

September 14, 2012
Tweet

Transcript

  1. Sugar-Free Ruby A Look at Object-First Teaching

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

    => "nuclearsandwich", "Freenode" => "nuclearsandwich", "Email" => "steven@nuclearsandwich.com", "WWW" => "www.nuclearsandwich.com", "Twitter" => "@nuclearsandwich" } ''That guy with all the opinions''
  3. Teaching Programming

  4. Why is teaching so damn hard?

  5. Why is teaching so damn hard? • It's hard to

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

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

    a lot of self reflection to teach well.
  8. Teaching Programming It's getting better

  9. Kids learn: • Game Builder • Scratch • Python •

    Hackety-Hack / Shoes
  10. Programming is fun

  11. • Workshops for Women • Kids Ruby • Workshops /

    Curriculum in other languages
  12. Programming is hard… But only this hard

  13. RailsBridge: Workshops for Women • Install all the things the

    night before • One full day • Focus on Ruby, Rails, or split based on experience
  14. Teaching Ruby The challenge

  15. Why do you want to learn Ruby?

  16. Why do you want to learn Ruby? • I hate

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

    my job and hear programmers make bank • I know how to program but not Ruby
  18. 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
  19. Disclaimer This point onward: Open minds only

  20. Disclaimer Haters, the doors are stage left

  21. Teaching Ruby The (Good?) Old Fashioned Way

  22. Numbers 5 + 5 #=> 10 9 / 2 #=>

    4 9.0 / 2 #=> 4.5
  23. Strings and Symbols 'Hello' #=> "Hello" :what? #=> :what? "Hello,

    " + "World!" #=> "Hello, World!"
  24. Boolean Values true #=> true false #=> false 20 <

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

    :name => "Steven!", :age => 24, :species => "human" }
  26. Variable Assignment my_name = "Steven!" my_age = 24

  27. Variable Access # ten years from now my_age + 10

    #=> 34 # I hashify myself { :name => my_name, :age => my_age } #=> {:name => "Steven!", # :age => 24}
  28. Console Output puts my_name Steven! #=> nil puts my_age +

    10 34 #=> nil
  29. Conditionals if my_name == "Steven!" puts "Hello!" else puts "Who

    are you?" end Hello! #=> nil
  30. Loops while my_age < 30 do puts "Enjoying my twenties"

    my_age = my_age + 1 end
  31. Methods "foo".upcase #=> "FOO"

  32. Teaching Ruby What's wrong with this picture?

  33. What's wrong with this picture? Six whole concepts come before

    methods.
  34. What's wrong with this picture? No mention whatsoever of classes.

  35. What's wrong with this picture? Why do we cling to

    this?
  36. Ruby is not a computer language.

  37. Ruby is not a computer language. So why are we

    teaching it like one?
  38. Teaching Objects Ruby is the computer

  39. But Steven!, If we try to teach all of that

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

    "Hello!" #=> "Hello!" [1, 2, 3] #=> [1, 2, 3]
  41. They Receive Messages "six".send :upcase #=> "SIX" 5.send :+, 9

    #=> 14 17.send :nil? #=> false
  42. Objects Have (a) Class 5.send :class #=> Fixnum 4.0.send :class

    #=> Float ["he's", "crazy?"].send :class #=> Array
  43. Teaching Objects The pen and the scribe

  44. Instantiation pen = Object.new #=> #<Object:0x007ff1c491de90>

  45. Method Definition def pen.to_s "A trusty pen" end #=> nil

  46. Message Sending pen.send :to_s #=> A trusty pen

  47. A Pinch of Sugar def pen.to_s "A trusty pen" end

    pen.to_s #=> A trusty pen
  48. Errors Are Your Friends pen.write "Hi there" #=> NoMethodError: undefined

    # method `write' for # A trusty pen:Object
  49. Use the Kernel, Luke def pen.write thing Kernel.puts thing end

    #=> nil
  50. Write Anything! pen.write "Hi" Hi #=> nil pen.write pen A

    trusty pen #=> nil
  51. 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
  52. Showing Our Colors def pen.to_s "A trusty #{@ink_color} pen" end

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

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

    \ #{@ink_color};\"> #{thing} </p>" else "<p>#{thing}</p>" end end
  55. Teaching Ruby What have we introduced?

  56. 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
  57. …you blockhead # in the Scribe class body def write_everything

    @items.each do |item| @pen.write item end end end #=> Scribe
  58. 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
  59. Teaching Ruby with Objects

  60. Teaching Objects with Ruby

  61. Why is this better? The object metaphor provides a context

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

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

    new things (like syntactic sugar) are more readily digestible
  64. Thanks! Behind the Scenes X E L A TEX/ Beamer

    Pygments / Minted