My Daughter’s First Pair Programming Session
My daughter was very disappointed that she lost a game of Chutes & Ladders. She hit the biggest slide, then the biggest ladder then tied my wife in race to roll a 1 – it was a very exciting game. After some tears we had the following conversation:
- Daddy
- I can see you’re very disappointed. What do you think we should do about it?
- Piper
- I want it so that I was the the winner of the game.
- Daddy
- Ok.
- Piper
- Wha?
- Daddy
- You’re the winner.
- Piper
- Pauses. Then starts to cry. I still feel frustrated!
- Daddy
- That’s because you didn’t really win.
- Piper
- We should play it again but I’ll win this time.
- Daddy
- Ok.
- Piper
- Wha?
- Daddy
- But I’m unclear on how to do it. Maybe you can help me figure it out.
- Piper
- When we play, I’ll win.
- Daddy
- Right. So you’ll spin the numbers and those numbers will make you win.
- Piper
- Yes.
- Daddy
- How do we make the spinner know you’re the one spinning it?
- Piper
- Pauses We’ll make a machine that knows.
- Daddy
- Cool idea! Where do we get that machine?
- Piper
- We have to make it.
- Daddy
- Ok. How do we make it?
- Piper
- We get blueprints like on Phineas and Ferb and follow the instructions.
- Daddy
- You know. My job is to make blueprints for a kind of machine that runs in a computer called a program.
- Piper
- Really?
- Daddy
- Yep. Do you want to help me make a machine that plays a game where you always win?
- Piper
- Big Grin Sure!
- Daddy
- Begins Coding Ok. So how will it know if you’re playing?
- Piper
- It’ll ask our own names.
- Daddy
- Ok. So you’ll type it in?
- Piper
- Yes.
- Daddy
- And what if I was to type your name in? (I’m hoping she’ll invent passwords)
- Piper
- Pauses That’s not nice to do.
- Daddy
- No it’s not. So we type our names in and if you’re playing, you win?
- Piper
- Yep.
- Daddy
- types for a few minutes Ok. Let’s play!
We played the game about 10 times. Each time we played, she won. Now I have to admit that my goal was that she would discover that a rigged game wasn’t fun to win and that winning is fun because there is losing. But each time she won, she beamed with happiness. A bit disappointed I talked her thru how the program worked. Then content at her perfect success at our game she said “I’m ready for books now.”
Here’s the program we wrote:
print "How many players? "
$stdout.flush
number_of_players = gets.strip.to_i
player_names = []
number_of_players.times do
print "What is the name of player ##{player_names.size + 1}? "
player_names << gets.strip
end
if piper = player_names.grep(/piper/i).first
puts "#{piper} wins!!!"
else
puts "#{player_names[(number_of_players * rand).to_i]} wins!!!"
end
And some of the console log:
[master][~/Projects/piper] ruby only_piper_wins.rb
How many players? 2
What is the name of player #1? daddy
What is the name of player #2? piper
piper wins!!!
[master][~/Projects/piper] ruby only_piper_wins.rb
How many players? 3
What is the name of player #1? mommy
What is the name of player #2? daddy
What is the name of player #3? piper
piper wins!!!
[master][~/Projects/piper] ruby only_piper_wins.rb
How many players? 3
What is the name of player #1? mommy
What is the name of player #2? chris
What is the name of player #3? piper
piper wins!!!
[master][~/Projects/piper] ruby only_piper_wins.rb
How many players? 2
What is the name of player #1? daddy
What is the name of player #2? mommy
daddy wins!!!
[master][~/Projects/piper] ruby only_piper_wins.rb
How many players? 3
What is the name of player #1? mommy
What is the name of player #2? piper
What is the name of player #3? daddy
piper wins!!!
[master][~/Projects/piper] ruby only_piper_wins.rb
How many players? 2
What is the name of player #1? mmmommmy
What is the name of player #2? piper
piper wins!!!
# I mention I'm sad that I never win so she changes her name to mommy
[master][~/Projects/piper] ruby only_piper_wins.rb
How many players? 2
What is the name of player #1? mommy
What is the name of player #2? daddy
mommy wins!!!
[master][~/Projects/piper] ruby only_piper_wins.rb
How many players? 2
What is the name of player #1? daddy
What is the name of player #2? mommy
mommy wins!!!
About Me
I am an open source hacker and stylesheet architect at LinkedIn. I live in San Jose, California with my wife and daughter.
Open Source
I'm the creator of Compass, a stylesheet authoring framework and I'm on the core team of Sass — the stylesheet syntax upon which Compass is built. I maintain about a dozen less well known ruby libraries and rails plugins on github, and am an active contributor of patches to the many open source projects that I use.