Milano Legacy Coderetreat 2013
-
Upload
gabriele-lana -
Category
Technology
-
view
928 -
download
2
Transcript of Milano Legacy Coderetreat 2013
LegacyCoderetreatMilano 2013
Text
10 PRINT "Hello World"20 Go to 10
#lcrm13
Format of the Day
from 10:00 to 13:00
MORNING
from 13:00 to 14:00
LUNCH
from 14:00 to 17:00
AFTERNOON
45 min coding10 min retrospective5 min break
Format of the Day
45’ coding10’ review5’ break
•CHALLENGE•REPEAT•FEEDBACK
DEEPPRACTICE
NO PRESSURE
feel free toexperiment
NO PRESSUREdo not completethe task but master it
Practice
Refactoring
•AUTOMATIC•MANUAL
Read Code
TestCode
CharacterizeBehaviour
Design
•BY CODE•BY TESTS•BY SMELLS
Rules
When youdon’tpair...
aftereach
session
Pair
DELETEYOURCODEAFTEREACHSESSION
Playbook
Golden Master(aka characterization tests)
session #1
# suppose that our legacy code is this program called ‘game’$ game > GOLDEN_MASTER
# after some changes we can check to see if behaviour has changed$ game > OUT-01$ diff GOLDEN_MASTER OUT-01
# after some other changes we check again and...$ game > OUT-02$ diff GOLDEN_MASTER OUT-02
# GOLDEN_MASTER and OUT-01 are the same
# GOLDEN_MASTER and OUT-02 are different -> behaviour changed
Golden Master(aka characterization tests)
# what about something with a random output?$ whatthecommit> I think I fixed a bug :-)> for great justice.> syntax> LOL!> ...
# somewhere in the code...$ cat whatthecommit | ack -i ‘rand’> 5: g = Random.new> 42: messages[g.rand(NUMBER_OF_MESSAGES)]
Golden Master(aka characterization tests)
# sequence generators are initialized with a seed# two random sequence generators initialized with the same# seed are going to produce the same sequence of numbers
$ irb1.9.3 > g = Random.new1.9.3 > (1..10).map{g.rand(1000)} => [691, 362, 997, 692, 236, 532, 687, 616, 218, 702]1.9.3 > g = Random.new 1.9.3 > (1..10).map{g.rand(1000)} => [865, 186, 89, 382, 894, 708, 769, 850, 452, 85] 1.9.3 > g = Random.new(1)1.9.3 > (1..10).map{g.rand(1000)} => [37, 235, 908, 72, 767, 905, 715, 645, 847, 960] 1.9.3 > g = Random.new(1)1.9.3 > (1..10).map{g.rand(1000)} => [37, 235, 908, 72, 767, 905, 715, 645, 847, 960]
Golden Master(aka characterization tests)
# we need to change the code to take somehow the seed $ whatthecommit --seed=42> fix the bug, for realz> to those I leave behind, good luck!> herping the derp> changes> ...
# so that with the same seed, the same code is going to# create the same output$ whatthecommit --seed=42> fix the bug, for realz> to those I leave behind, good luck!> herping the derp> changes> ...
Golden Master(aka characterization tests)
$ git clone https://github.com/gabrielelana/trivia.git$ cd triva# enjoy
session #1Characterize the behaviour of the code with the golden master technique
Test Code
# to get the already done golden master$ git merge golden-master
session #2
Refactoring & Design
Refactor the code so that it will be easy to create a newcategory of questions
session #3
Test Code
Put undertest therollmethod/function
session #4
Read Code
Mark all the smells in the code. Remove at least 3 of them
session #5
Remove all the duplication
session #6Replacing the penalty rules should be a one line change!