Slide 1

Slide 1 text

Sugar-Free Ruby A Look at Object-First Teaching

Slide 2

Slide 2 text

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''

Slide 3

Slide 3 text

Teaching Programming

Slide 4

Slide 4 text

Why is teaching so damn hard?

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

Why is teaching so damn hard? • It's hard to remember learning to program • It's hard to share knowledge instead of guard it

Slide 7

Slide 7 text

Why is teaching so damn hard? In short: it takes a lot of self reflection to teach well.

Slide 8

Slide 8 text

Teaching Programming It's getting better

Slide 9

Slide 9 text

Kids learn: • Game Builder • Scratch • Python • Hackety-Hack / Shoes

Slide 10

Slide 10 text

Programming is fun

Slide 11

Slide 11 text

• Workshops for Women • Kids Ruby • Workshops / Curriculum in other languages

Slide 12

Slide 12 text

Programming is hard… But only this hard

Slide 13

Slide 13 text

RailsBridge: Workshops for Women • Install all the things the night before • One full day • Focus on Ruby, Rails, or split based on experience

Slide 14

Slide 14 text

Teaching Ruby The challenge

Slide 15

Slide 15 text

Why do you want to learn Ruby?

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

Disclaimer This point onward: Open minds only

Slide 20

Slide 20 text

Disclaimer Haters, the doors are stage left

Slide 21

Slide 21 text

Teaching Ruby The (Good?) Old Fashioned Way

Slide 22

Slide 22 text

Numbers 5 + 5 #=> 10 9 / 2 #=> 4 9.0 / 2 #=> 4.5

Slide 23

Slide 23 text

Strings and Symbols 'Hello' #=> "Hello" :what? #=> :what? "Hello, " + "World!" #=> "Hello, World!"

Slide 24

Slide 24 text

Boolean Values true #=> true false #=> false 20 < 100 #=> true true and false #=> false true or false #=> true

Slide 25

Slide 25 text

Arrays and Hashes [ 1, 2, 3.0, "four" ] { :name => "Steven!", :age => 24, :species => "human" }

Slide 26

Slide 26 text

Variable Assignment my_name = "Steven!" my_age = 24

Slide 27

Slide 27 text

Variable Access # ten years from now my_age + 10 #=> 34 # I hashify myself { :name => my_name, :age => my_age } #=> {:name => "Steven!", # :age => 24}

Slide 28

Slide 28 text

Console Output puts my_name Steven! #=> nil puts my_age + 10 34 #=> nil

Slide 29

Slide 29 text

Conditionals if my_name == "Steven!" puts "Hello!" else puts "Who are you?" end Hello! #=> nil

Slide 30

Slide 30 text

Loops while my_age < 30 do puts "Enjoying my twenties" my_age = my_age + 1 end

Slide 31

Slide 31 text

Methods "foo".upcase #=> "FOO"

Slide 32

Slide 32 text

Teaching Ruby What's wrong with this picture?

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

Ruby is not a computer language.

Slide 37

Slide 37 text

Ruby is not a computer language. So why are we teaching it like one?

Slide 38

Slide 38 text

Teaching Objects Ruby is the computer

Slide 39

Slide 39 text

But Steven!, If we try to teach all of that and Objects, their heads will explode!

Slide 40

Slide 40 text

Everything is an Object 5 #=> 5 42.0 #=> 42.0 "Hello!" #=> "Hello!" [1, 2, 3] #=> [1, 2, 3]

Slide 41

Slide 41 text

They Receive Messages "six".send :upcase #=> "SIX" 5.send :+, 9 #=> 14 17.send :nil? #=> false

Slide 42

Slide 42 text

Objects Have (a) Class 5.send :class #=> Fixnum 4.0.send :class #=> Float ["he's", "crazy?"].send :class #=> Array

Slide 43

Slide 43 text

Teaching Objects The pen and the scribe

Slide 44

Slide 44 text

Instantiation pen = Object.new #=> #

Slide 45

Slide 45 text

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

Slide 46

Slide 46 text

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

Slide 47

Slide 47 text

A Pinch of Sugar def pen.to_s "A trusty pen" end pen.to_s #=> A trusty pen

Slide 48

Slide 48 text

Errors Are Your Friends pen.write "Hi there" #=> NoMethodError: undefined # method `write' for # A trusty pen:Object

Slide 49

Slide 49 text

Use the Kernel, Luke def pen.write thing Kernel.puts thing end #=> nil

Slide 50

Slide 50 text

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

Slide 51

Slide 51 text

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

Slide 52

Slide 52 text

Showing Our Colors def pen.to_s "A trusty #{@ink_color} pen" end pen.ink_color = "purple" #=> "purple" pen #=> "A trusty purple pen"

Slide 53

Slide 53 text

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

Slide 54

Slide 54 text

Conditionals Revisited def pen.html_write thing write if @ink_color "

#{thing}

" else "

#{thing}

" end end

Slide 55

Slide 55 text

Teaching Ruby What have we introduced?

Slide 56

Slide 56 text

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

Slide 57

Slide 57 text

…you blockhead # in the Scribe class body def write_everything @items.each do |item| @pen.write item end end end #=> Scribe

Slide 58

Slide 58 text

Hiring a new scribe mielot = Scribe.new 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

Slide 59

Slide 59 text

Teaching Ruby with Objects

Slide 60

Slide 60 text

Teaching Objects with Ruby

Slide 61

Slide 61 text

Why is this better? The object metaphor provides a context for everything else we learn about Ruby

Slide 62

Slide 62 text

Why is this better? We don't bombard them with new concepts until just before their use

Slide 63

Slide 63 text

Why is this better? With a thorough understanding of semantics, new things (like syntactic sugar) are more readily digestible

Slide 64

Slide 64 text

Thanks! Behind the Scenes X E L A TEX/ Beamer Pygments / Minted