Practice techniques in other crafts

David Chelimsky
November 19, 2011
SCNA

Martial Arts

any of the traditional forms of Oriental self-defense or combat that utilize physical skill and coordination without weapons, as karate, aikido, judo, or kung fu, often practiced as sport.

Marshall artist, I am not
David Chelimsky, SCNA 2011

My story


Music (grade school)

Magic (middle school and high school)

Theatre (high school and college)

Music (college and beyond)


Software (much later)

Performing arts

Improvisation

Improvisation is the art of using existing tools, skills and experience to spontaneously create something relevant to the current context.

We improvise when we converse - using words, grammar and common idioms to convey ideas. We improvise in music by using scales, chords and common idioms to (one might argue) convey ideas.

We improvise in software in the same way. There are many ways to express an idea in software, and so we tap into our tools, skills and experience to express the idea in the way that is most relevant to the context.

TDD

Improvisation in software

Practice techniques of improvising musicians

David Chelimsky
November 19, 2011
SCNA

Musicians spend most of their careers practicing.


Software developers spend most of their careers performing.

... it definitely is the most important thing to be able to have great technique, because if you don’t have good technique, you can’t execute what’s in your head. What good is that?
Al DiMeola
It never seemed to make sense to me why you'd be playing a scale up and down when you could be playing a tune.
Pat Metheny
Source: Guitar Player Magazine - December, 1981
I listen to [John] Coltrane, Joe Henderson, Sonny Rollins
Michael Brecker
Source: http://www.youtube.com/embed/hfgfo1cj_BQ (video interview)

Excerpts

Mediterranean Sundance - solo by Al Di Meola (0:50)

Third Wind - solo by Pat Metheny (1:16)

Nothing Personal - solo by Michael Brecker (2:23)

Technique (Basics)

Play a tune

http://www.rubyquiz.com/

156 problems to choose from



  • Calcuations
  • Validations
  • Reductions/Searches
  • Transformations
    • Visualization
    • [De]Serialization
  • Games
    • Single Player
    • Virtual Player
    • Generation
  • Path analysis/reduction
  • Cryptography

Constraints

Problems * Constraints

No primitives Two line method max Functional etc
Conway
Bowling
Codebreaker
English Numerals
etc

Work through a single problem applying different constraints each time.

Work through multiple problems applying the same constraint to each.

Listen to the masters

bowling / traditional OO style / ruby

describe Game do
  it "scores 0 for a gutter game" do
    game = Game.new
    20.times { game.roll(0) }
    game.score.should eq(0)
  end
end

class Game
  def initialize
    @rolls = []
  end

  def roll(pins)
    @rolls << pins
  end

  def score
    # ...

bowling / traditional OO style / ruby

  def score
    score = 0
    index = 0
    10.times do
      if strike_at?(index)
        score += 10 + bonus_for_strike_at(index)
      elsif spare_at?(index)
        score += 10 + bonus_for_spare_at(index)
      else
        score += two_rolls_at(index)
      end
      index += 2
    end
    score
  end

bowling / functional style / ruby

describe "bowling" do
  it "scores 0 for a gutter game" do
    game = make_game
    20.times { roll(game, 0) }
    score(game).should eq(0)
  end
end

bowling / functional style / ruby

def make_game; [] end

def roll(game, pins); game << pins end

def score(game)
  frames(game).map(&:score).sum
end

def frames(rolls, frame=0)
  return [] if frame == 10
  next_frame(rolls, score_size(rolls)) + 
    frames(rolls.drop(frame_size(rolls)), frame + 1)
end

bowling / functional style / ruby

def next_frame(rolls, score_size)
  [rolls.take(score_size)]
end

def strike?(rolls); rolls.sum(1) == 10 end
def spare?(rolls);  rolls.sum(2) == 10 end

def score_size(rolls)
  strike?(rolls) || spare?(rolls) ? 3 : 2
end

def frame_size(rolls)
  strike?(rolls) ? 1 : 2
end

bowling / functional style / ruby

class Array.send :include, Module.new {
  def sum(n=size, &block)
    block ? map(&block).sum : take(n).inject(0, :+)
  end

  alias_method :score, :sum
}

repeat the least comfortable part of a kata

def score
  @rolls.inject {|sum,pins| sum + pins}
end
def score
  score = 0
  index = 0
  10.times do
    if spare_at?(index)
      score += 10 + bonus_for_spare_at(index)
    else
      score += two_rolls_at(index)
    end
    index += 2
  end
  score
end