KEMBAR78
Python Coding Dojo - 2014-03-19 | ODP
Python Coding Dojo
March 19th
, 2014
PyUGAT
Coding Dojo?
Code!
Learn!
Have fun!
Coding Dojo?
● Safe place, not work
● Our Goal: to learn
● Not our goal: to finish the task
Practices
● Test-Driven Development
● Pair Programming
Test-Driven Development
Overview
Analyse Problem
Test List
Guiding Test
Red
Declare & Name
Arrange-Act-Assert
Satisfy compiler
Green
Implement solution
Fake it
Start over
Refactor
Remove Fake
Remove Code Smell
(No new functionality)
Note new test cases
Test-Driven Development
from nose.tools import *
import fizzbuzz
def test_1_returns_1():
    result = fizzbuzz.fizzbuzz(1)
    assert_equal(result, "1")
Test-Driven Development
def fizzbuzz(number):
    return "1"
Test-Driven Development
[…]
def test_2_returns_2():
    result = fizzbuzz.fizzbuzz(2)
    assert_equal(result, "2")
Test-Driven Development
def fizzbuzz(number):
    return str(number)
Test-Driven Development
[…]
def test_3_returns_Fizz():
    result = fizzbuzz.fizzbuzz(3)
    assert_equal(result, "Fizz")
Test-Driven Development
def fizzbuzz(number):
    if number == 3:
        return "Fizz"
    return str(number)
What will be the next test?
Pair Programming
● Driver: types at the computer
● Navigator
– Looks for:
● Tactical defects: Syntax errors, Typos, Calling the wrong
method
● Strategic defects in the driver's work
– Driver's implementation or design fails to accomplish its goal
– Strategic, long-range thinker of the pair
● Effective Pair: Constantly discusses alternative
approaches and solutions to the problem
● Dysfunctional Pair: Quiet navigator
Kata: „Word Wrap“
You write a class called Wrapper, that has a single static
function named wrap that takes two arguments, a string,
and a column number. The function returns the string,
but with line breaks inserted at just the right places to
make sure that no line is longer than the column
number. You try to break lines at word boundaries.
Like a word processor, break the line by replacing the
last space in a line with a newline.
Randori
● 10 min introduction
● 10 min discussion
● 40 min working on the problem
– 1 driver, 1 navigator
– Every 5 min
● driver → audience
● navigator → driver
● audience (1 person) → navigator
● 5 min break
● 40 min working on the problem
– Like before
● 15 min retrospective
Randori in Pairs
● Coding
– Split into pairs
– Work on the Kata for 45 minutes
– 5 minutes debriefing
● 5 minutes break
● Coding
– Split into pairs
– Work on the Kata for 45 minutes
– 5 minutes debriefing
● 10 minutes retrospective
Happy Coding!
Retrospective
● Are you happy with the design of the code you ended up
with? Should you have refactored it more often?
● What are the best aspects of the design of the code
we've ended up with?
● Did we learn anything new?
● Did anything unexpected happen?
● What do we still need to practice more?
● What should we do differently in the next dojo?
● What will you do differently tomorrow in your production
code?

Python Coding Dojo - 2014-03-19