SlideShare une entreprise Scribd logo
1  sur  49
Télécharger pour lire hors ligne
Agile
Developer
Immersion
Refactoring
Victoria, Dan, and
Tomasz
Your Facilitators
Dan Prager
Agile Consultant @ Skillfire & ZXM
@agilejitsu
Victoria Schiffer
Delivery Manager @ SEEK
@Erdbeervogel
Tomasz Janowski
Technical Lead @ REA Group
@janowskit
Introduction
Ice-breaker
1. Pair up and invent a groovy handshake with
five distinct movements
2. Practice your handshake
3. Whip round the room and each pair does a
demo
Plan for the Day
Session A: 11 am — 12:30 pm
● Welcome & Ice-breaker
● Sprint 0: Golden Master testing (Victoria)
Lunch
Session B: 1:30 – 3 pm
● Sprint 1: Remove Duplication & Improve Names (Dan)
● Sprint 2: Extract to Pure Functions (Tomasz)
Afternoon tea
Session C: 3:30 – 5 pm
● Sprint 3: Add a Feature (Tomasz)
● Sprint 4: Group Debrief
What is Legacy Code?
“Legacy Code is code without tests.”— Michael Feathers
equivalently
“Legacy Code is code you are afraid to change.”— J B Rainsberger
Reflection: “What are some of the pros of Legacy Code?”
Comparison to Fundamentals Immersion
Similarities to Fundamentals / Regular Code Retreat
● One problem for the day
● Lots of sprints, with a different learning focus each sprint
● Pair programming, and rotate partners each sprint
● Huge focus on fast feedback through automated testing
Differences
● Instead of a spec, we start with a steaming pile of legacy code
● We do not delete our code at the end of each sprint!
● Emphasis on Golden Master testing technique
● Use of TDD is now selective, BUT still highly recommended
Sprint 0: Golden Master Testing
Why and What of Golden Master Testing
● Why it’s hard to get started to refactor legacy code
● What Golden Master testing is and how it helps us get started with Legacy Code
● Why Build your own Golden Master infrastructure
● What about TDD and unit testing?
Why it’s hard to get started to refactor
legacy code
● Lack of tests
● ‘Fear’ of changing anything
● Low confidence in not breaking anything
● Not sure what will break, which behaviours might be
impacted by the change
"In nearly every legacy system, what the system does is more
important than what it’s supposed to do.”
“A characterisation test is a test that characterizes the actual
behaviour of a piece of code"
— Michael C. Feathers, Working Effectively with Legacy Code
→ It isn’t right or wrong, it simply exists
Why a ‘Golden Master’?
“A gold master test is a regression test for complex, untested
systems that asserts a consistent macro-level behavior.”
— Jake Worth
→ black box test
What’s a Golden Master Test?
“Mastering, a form of audio post production, is the process of
preparing and transferring recorded audio from a source
containing the final mix to a data storage device (the master);
the source from which all copies will be produced.
‘Golden Master’ Analogy
Mastering requires critical listening; however, software tools exist to facilitate the process. Results still
depend upon the intent of the engineer, the accuracy of the speaker monitors, and the listening
environment. Mastering engineers may also need to apply corrective equalization and dynamic
compression in order to optimise sound translation on all playback systems. It is standard practice to
make a copy of a master recording, known as a safety copy, in case the master is lost, damaged or
stolen.” (Wikipedia)
Golden Record: NASA
● Every Golden Master is unique to the specific legacy
system and its behaviours
● Right level of output data captured and compared with
● Might need to scrub data (e.g. if using copy of production
database in your golden master)
Why Build Your Own Golden Master
Infrastructure?
What about TDD & Unit Testing?
Image: Martin Fowler
Working with Golden Master
Run Code/Test
Save as Golden
Master
Run Code/Test
Capture Data/Output
Compare to Golden
Master
Equal?
1st Run Subsequent Runs
Capture Data/Output
Prompts Decision: Re-Baseline Golden Master OR roll-back
Keep Refactoring.
No!
Yes!
Steps to building a Golden Master
1. Get the code to run
2. Randomly generate inputs, leading to plentiful output
● Fix the random number seed, leading to repeatable output
3. Capture the output of every run
● The output of the unmodified legacy system is your “Golden Master” (save it somewhere)
● Options for output capture: Roll your own “print” function and do a careful find & replace, or
○ Monkey patch “print”, or
○ Redirect stdout
4. Compare the captured output of each run to the Golden Master output
● Report success or failure → every failure prompts decision
● Report line(s) that don’t match, actual vs expected
5. Extension: Incorporate two golden-master tests in your unit test suite
● Line length of current run vs Golden Master length
● Expected empty diff (all lines match) vs Mis-matched lines
Capturing the output (JavaScript examples)
Find & Replace (41 replacements) Monkey patch console.log
Redirecting to stdout to a file (C# example)
Over to you!
Build your own Golden Master
● Pair up!
● Get the Legacy Code in your programming language of
choice http://github.com/lastconf2018/trivia
● Build your own Golden Master!
Sprint 1: Remove Duplication & Improve Names
Leaning on the Golden Master
Focus of the Sprint
1. Find code duplications and poor-namings and fix them
2. Keep re-running the Golden Master test to confirm that you haven’t changed the
system behaviour
Stretch activities
● Find and fix a subtle defect in the Legacy code
● Introduce a unit test
With Duplication
def current_category():
if places[current_player] == 0: return 'Pop'
if places[current_player] == 4: return 'Pop'
if places[current_player] == 8: return 'Pop'
if places[current_player] == 1: return 'Science'
if places[current_player] == 5: return 'Science'
if places[current_player] == 9: return 'Science'
if places[current_player] == 2: return 'Sports'
if places[current_player] == 6: return 'Sports'
if places[current_player] == 10: return 'Sports'
return 'Rock'
Refactored
def current_category():
position = places[current_player]
if position in [0,4,8]: return 'Pop'
if position in [1,5,9]: return 'Science'
if position in [2,6,10]: return 'Sports'
return 'Rock'
● Undo old cut & pastes!
● New code? “Rule of three”
Extract code snippets to a well-named function
; This code appears in several places (duplication)
...
places[current_player] = places[current_player] + roll
if places[current_player] > 11:
places[current_player] = places[current_player] - 12
...
def move_current_player_forward():
places[current_player] = places[current_player] + roll
if places[current_player] > 11:
places[current_player] = places[current_player] - 12 # the board wraps around
Now we have (in a few places):
...
move_current_player_forward()
...
Kent “XP” Beck’s four rules of Simple Design
Our Priorities
1. passes its tests
2. remove duplication
3. Improve names
4. Fewer functions, classes, etc.
Sprint 2: Pure functions
Extract to Pure Functions
● What they are
● Why they’re good: easy to unit test
● Pure functions + Commands + Glue
● Example(s)
Emphasis of the sprint:
1. Start adding unit tests around your pure functions
2. Stretch: TDD your pure functions
3. Keep using the Golden Master as a back-stop
Pure Functions
A pure function is a function where the
return value is only determined by its input
values, without observable side effects.
Pure Functions
● A pure function can only access what you pass it, so it’s easy to see
its dependencies.
● When a function accesses some other program state, such as a
global variable, it is no longer pure.
● A given invocation of a pure function can be replaced by its result.
There’s no difference between “add(2,3)” and “5”.
This property is called referential transparency
Testing
● To test a pure function, you declare the values that will act as
arguments and pass them to the function. The output value needs
to be verified against the expected value.
● No context to set up, no current user or request
● No side effects to mock or stub
● Testing doesn’t get more straightforward than this
Parallelization
● Pure functions can always be parallelized.
● No race conditions as there’s no shared state
Memoization
● Pure functions always return the same output for the same input
● We only need to compute the output once for given inputs
● Caching and reusing the result is called memoization and can only
be done safely with pure functions
Examples
function add(a, b) {
return a + b;
}
Examples
function add(a, b) {
formatHdd();
return a + b;
}
Examples
function doubleArray(arr) {
return arr.map((a) => a * 2);
}
Examples
function doubleArray(arr) {
for(let i = 0; i < arr.length; i++) {
arr[i] = arr[i] * 2;
}
return arr;
}
Examples
function rollDice() {
return Math.floor(Math.random() * 6) + 1;
}
Examples
function tomorrow() {
const now = new Date();
return new Date(now.getTime() +
(24 * 60 * 60 * 1000));
}
Examples
function tomorrow(now) {
return new Date(now.getTime() +
(24 * 60 * 60 * 1000));
}
Examples
function fullName(person) {
person.firstName = person.firstName.trim();
person.lastName = person.firstName.trim();
return person.firstName + ' ' + person.lastName;
}
Examples
function fullName(person) {
return person.firstName.trim() + ' ' +
person.lastName.trim();
}
Sprint 3: Add a feature
Add a feature (or two)
Use TDD to add a new feature. Your choice of
● New question categories: History, Politics, Religion
● Support more than 6 players
● Add an optional Polish or German translation
● Invent and add a new rule
Emphasis of the sprint
● Re-incorporating TDD for new features: don’t just lean on the Golden Master
● Re-baselining your Golden Master
Sprint 4: Group discussion
Split into two or three groups
How can we apply what we have learned in the “real world” of Work?
● Where might we use Golden Master testing?
● What additional adaptations would we need?
● What about other techniques?
● Cultural issues
Next steps
Feedback forms
Your honest and constructive feedback helps us to improve!
— Dan, Victoria, & Tomasz
Further learning
Complementary techniques
● Github Scientist / Branch by abstraction
● Design by Contract
● Property-based testing
● Mob Programming
● etc.
In-house immersions / training
● Talk to Dan! daniel.a.prager@gmail.com
GDCR 18
https://www.coderetreat.org

Contenu connexe

Tendances

Club of anonimous developers "Refactoring: Legacy code"
Club of anonimous developers "Refactoring: Legacy code"Club of anonimous developers "Refactoring: Legacy code"
Club of anonimous developers "Refactoring: Legacy code"Victor_Cr
 
Unit testing with Spock Framework
Unit testing with Spock FrameworkUnit testing with Spock Framework
Unit testing with Spock FrameworkEugene Dvorkin
 
Java 7 Language Enhancement
Java 7 Language EnhancementJava 7 Language Enhancement
Java 7 Language Enhancementmuthusvm
 
Drools, jBPM OptaPlanner presentation
Drools, jBPM OptaPlanner presentationDrools, jBPM OptaPlanner presentation
Drools, jBPM OptaPlanner presentationMark Proctor
 
The Ring programming language version 1.2 book - Part 80 of 84
The Ring programming language version 1.2 book - Part 80 of 84The Ring programming language version 1.2 book - Part 80 of 84
The Ring programming language version 1.2 book - Part 80 of 84Mahmoud Samir Fayed
 
Java 8 and beyond, a scala story
Java 8 and beyond, a scala storyJava 8 and beyond, a scala story
Java 8 and beyond, a scala storyittaiz
 
Non blocking programming and waiting
Non blocking programming and waitingNon blocking programming and waiting
Non blocking programming and waitingRoman Elizarov
 
The Ring programming language version 1.4 book - Part 19 of 30
The Ring programming language version 1.4 book - Part 19 of 30The Ring programming language version 1.4 book - Part 19 of 30
The Ring programming language version 1.4 book - Part 19 of 30Mahmoud Samir Fayed
 
Java → kotlin: Tests Made Simple
Java → kotlin: Tests Made SimpleJava → kotlin: Tests Made Simple
Java → kotlin: Tests Made Simpleleonsabr
 
DSR Testing (Part 1)
DSR Testing (Part 1)DSR Testing (Part 1)
DSR Testing (Part 1)Steve Upton
 
Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011Agora Group
 
The Ring programming language version 1.9 book - Part 10 of 210
The Ring programming language version 1.9 book - Part 10 of 210The Ring programming language version 1.9 book - Part 10 of 210
The Ring programming language version 1.9 book - Part 10 of 210Mahmoud Samir Fayed
 
01 Java Language And OOP Part I LAB
01 Java Language And OOP Part I LAB01 Java Language And OOP Part I LAB
01 Java Language And OOP Part I LABHari Christian
 
Test Driven Development iOS에 적용해보기
Test Driven Development  iOS에 적용해보기Test Driven Development  iOS에 적용해보기
Test Driven Development iOS에 적용해보기Bob Lee
 
The Ring programming language version 1.10 book - Part 11 of 212
The Ring programming language version 1.10 book - Part 11 of 212The Ring programming language version 1.10 book - Part 11 of 212
The Ring programming language version 1.10 book - Part 11 of 212Mahmoud Samir Fayed
 
What to expect from Java 9
What to expect from Java 9What to expect from Java 9
What to expect from Java 9Ivan Krylov
 
02 Java Language And OOP Part II LAB
02 Java Language And OOP Part II LAB02 Java Language And OOP Part II LAB
02 Java Language And OOP Part II LABHari Christian
 

Tendances (20)

Club of anonimous developers "Refactoring: Legacy code"
Club of anonimous developers "Refactoring: Legacy code"Club of anonimous developers "Refactoring: Legacy code"
Club of anonimous developers "Refactoring: Legacy code"
 
Java concurrency
Java concurrencyJava concurrency
Java concurrency
 
Unit testing with Spock Framework
Unit testing with Spock FrameworkUnit testing with Spock Framework
Unit testing with Spock Framework
 
Java 7 Language Enhancement
Java 7 Language EnhancementJava 7 Language Enhancement
Java 7 Language Enhancement
 
Java 101
Java 101Java 101
Java 101
 
Drools, jBPM OptaPlanner presentation
Drools, jBPM OptaPlanner presentationDrools, jBPM OptaPlanner presentation
Drools, jBPM OptaPlanner presentation
 
The Ring programming language version 1.2 book - Part 80 of 84
The Ring programming language version 1.2 book - Part 80 of 84The Ring programming language version 1.2 book - Part 80 of 84
The Ring programming language version 1.2 book - Part 80 of 84
 
Java 8 and beyond, a scala story
Java 8 and beyond, a scala storyJava 8 and beyond, a scala story
Java 8 and beyond, a scala story
 
Non blocking programming and waiting
Non blocking programming and waitingNon blocking programming and waiting
Non blocking programming and waiting
 
The Ring programming language version 1.4 book - Part 19 of 30
The Ring programming language version 1.4 book - Part 19 of 30The Ring programming language version 1.4 book - Part 19 of 30
The Ring programming language version 1.4 book - Part 19 of 30
 
Java → kotlin: Tests Made Simple
Java → kotlin: Tests Made SimpleJava → kotlin: Tests Made Simple
Java → kotlin: Tests Made Simple
 
DSR Testing (Part 1)
DSR Testing (Part 1)DSR Testing (Part 1)
DSR Testing (Part 1)
 
Spock Framework
Spock FrameworkSpock Framework
Spock Framework
 
Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011
 
The Ring programming language version 1.9 book - Part 10 of 210
The Ring programming language version 1.9 book - Part 10 of 210The Ring programming language version 1.9 book - Part 10 of 210
The Ring programming language version 1.9 book - Part 10 of 210
 
01 Java Language And OOP Part I LAB
01 Java Language And OOP Part I LAB01 Java Language And OOP Part I LAB
01 Java Language And OOP Part I LAB
 
Test Driven Development iOS에 적용해보기
Test Driven Development  iOS에 적용해보기Test Driven Development  iOS에 적용해보기
Test Driven Development iOS에 적용해보기
 
The Ring programming language version 1.10 book - Part 11 of 212
The Ring programming language version 1.10 book - Part 11 of 212The Ring programming language version 1.10 book - Part 11 of 212
The Ring programming language version 1.10 book - Part 11 of 212
 
What to expect from Java 9
What to expect from Java 9What to expect from Java 9
What to expect from Java 9
 
02 Java Language And OOP Part II LAB
02 Java Language And OOP Part II LAB02 Java Language And OOP Part II LAB
02 Java Language And OOP Part II LAB
 

Similaire à Agile Developer Immersion Workshop, LASTconf Melbourne, Australia, 19th July 2018

Unit Testing like a Pro - The Circle of Purity
Unit Testing like a Pro - The Circle of PurityUnit Testing like a Pro - The Circle of Purity
Unit Testing like a Pro - The Circle of PurityVictor Rentea
 
2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easier2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easierChristian Hujer
 
Testing Zen
Testing ZenTesting Zen
Testing Zenday
 
Gradle For Beginners (Serbian Developer Conference 2013 english)
Gradle For Beginners (Serbian Developer Conference 2013 english)Gradle For Beginners (Serbian Developer Conference 2013 english)
Gradle For Beginners (Serbian Developer Conference 2013 english)Joachim Baumann
 
Tdd is not about testing (OOP)
Tdd is not about testing (OOP)Tdd is not about testing (OOP)
Tdd is not about testing (OOP)Gianluca Padovani
 
Performance Tuning and Optimization
Performance Tuning and OptimizationPerformance Tuning and Optimization
Performance Tuning and OptimizationMongoDB
 
Advance unittest
Advance unittestAdvance unittest
Advance unittestReza Arbabi
 
Behaviour Driven Development and Thinking About Testing
Behaviour Driven Development and Thinking About TestingBehaviour Driven Development and Thinking About Testing
Behaviour Driven Development and Thinking About Testingdn
 
Bdd and-testing
Bdd and-testingBdd and-testing
Bdd and-testingmalcolmt
 
BarcelonaJUG2016: walkmod: how to run and design code transformations
BarcelonaJUG2016: walkmod: how to run and design code transformationsBarcelonaJUG2016: walkmod: how to run and design code transformations
BarcelonaJUG2016: walkmod: how to run and design code transformationswalkmod
 
Effective testing for spark programs scala bay preview (pre-strata ny 2015)
Effective testing for spark programs scala bay preview (pre-strata ny 2015)Effective testing for spark programs scala bay preview (pre-strata ny 2015)
Effective testing for spark programs scala bay preview (pre-strata ny 2015)Holden Karau
 
Performance Optimization of Rails Applications
Performance Optimization of Rails ApplicationsPerformance Optimization of Rails Applications
Performance Optimization of Rails ApplicationsSerge Smetana
 
New Ideas for Old Code - Greach
New Ideas for Old Code - GreachNew Ideas for Old Code - Greach
New Ideas for Old Code - GreachHamletDRC
 
Native Java with GraalVM
Native Java with GraalVMNative Java with GraalVM
Native Java with GraalVMSylvain Wallez
 
Grails unit testing
Grails unit testingGrails unit testing
Grails unit testingpleeps
 
Testing and validating spark programs - Strata SJ 2016
Testing and validating spark programs - Strata SJ 2016Testing and validating spark programs - Strata SJ 2016
Testing and validating spark programs - Strata SJ 2016Holden Karau
 
TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012Pietro Di Bello
 
C++ Testing Techniques Tips and Tricks - C++ London
C++ Testing Techniques Tips and Tricks - C++ LondonC++ Testing Techniques Tips and Tricks - C++ London
C++ Testing Techniques Tips and Tricks - C++ LondonClare Macrae
 
How and what to unit test
How and what to unit testHow and what to unit test
How and what to unit testEugenio Lentini
 

Similaire à Agile Developer Immersion Workshop, LASTconf Melbourne, Australia, 19th July 2018 (20)

Unit Testing like a Pro - The Circle of Purity
Unit Testing like a Pro - The Circle of PurityUnit Testing like a Pro - The Circle of Purity
Unit Testing like a Pro - The Circle of Purity
 
2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easier2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easier
 
Testing Zen
Testing ZenTesting Zen
Testing Zen
 
Gradle For Beginners (Serbian Developer Conference 2013 english)
Gradle For Beginners (Serbian Developer Conference 2013 english)Gradle For Beginners (Serbian Developer Conference 2013 english)
Gradle For Beginners (Serbian Developer Conference 2013 english)
 
Tdd is not about testing (OOP)
Tdd is not about testing (OOP)Tdd is not about testing (OOP)
Tdd is not about testing (OOP)
 
Performance Tuning and Optimization
Performance Tuning and OptimizationPerformance Tuning and Optimization
Performance Tuning and Optimization
 
Advance unittest
Advance unittestAdvance unittest
Advance unittest
 
Behaviour Driven Development and Thinking About Testing
Behaviour Driven Development and Thinking About TestingBehaviour Driven Development and Thinking About Testing
Behaviour Driven Development and Thinking About Testing
 
Bdd and-testing
Bdd and-testingBdd and-testing
Bdd and-testing
 
BarcelonaJUG2016: walkmod: how to run and design code transformations
BarcelonaJUG2016: walkmod: how to run and design code transformationsBarcelonaJUG2016: walkmod: how to run and design code transformations
BarcelonaJUG2016: walkmod: how to run and design code transformations
 
Effective testing for spark programs scala bay preview (pre-strata ny 2015)
Effective testing for spark programs scala bay preview (pre-strata ny 2015)Effective testing for spark programs scala bay preview (pre-strata ny 2015)
Effective testing for spark programs scala bay preview (pre-strata ny 2015)
 
Performance Optimization of Rails Applications
Performance Optimization of Rails ApplicationsPerformance Optimization of Rails Applications
Performance Optimization of Rails Applications
 
New Ideas for Old Code - Greach
New Ideas for Old Code - GreachNew Ideas for Old Code - Greach
New Ideas for Old Code - Greach
 
Native Java with GraalVM
Native Java with GraalVMNative Java with GraalVM
Native Java with GraalVM
 
Grails unit testing
Grails unit testingGrails unit testing
Grails unit testing
 
Testing and validating spark programs - Strata SJ 2016
Testing and validating spark programs - Strata SJ 2016Testing and validating spark programs - Strata SJ 2016
Testing and validating spark programs - Strata SJ 2016
 
Twins: OOP and FP
Twins: OOP and FPTwins: OOP and FP
Twins: OOP and FP
 
TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012TDD reloaded - JUGTAA 24 Ottobre 2012
TDD reloaded - JUGTAA 24 Ottobre 2012
 
C++ Testing Techniques Tips and Tricks - C++ London
C++ Testing Techniques Tips and Tricks - C++ LondonC++ Testing Techniques Tips and Tricks - C++ London
C++ Testing Techniques Tips and Tricks - C++ London
 
How and what to unit test
How and what to unit testHow and what to unit test
How and what to unit test
 

Plus de Victoria Schiffer

(Open Sourced) Cyber Scavenger Hunt - Gamified Security Awareness, even on a ...
(Open Sourced) Cyber Scavenger Hunt - Gamified Security Awareness, even on a ...(Open Sourced) Cyber Scavenger Hunt - Gamified Security Awareness, even on a ...
(Open Sourced) Cyber Scavenger Hunt - Gamified Security Awareness, even on a ...Victoria Schiffer
 
(Open Sourced) Cyber Scavenger Hunt - Gamified Security Awareness, even on a ...
(Open Sourced) Cyber Scavenger Hunt - Gamified Security Awareness, even on a ...(Open Sourced) Cyber Scavenger Hunt - Gamified Security Awareness, even on a ...
(Open Sourced) Cyber Scavenger Hunt - Gamified Security Awareness, even on a ...Victoria Schiffer
 
Melbourne, Australia Global Day of Code Retreat 2018 gdcr18 - Event Slides
Melbourne, Australia Global Day of Code Retreat 2018 gdcr18 - Event SlidesMelbourne, Australia Global Day of Code Retreat 2018 gdcr18 - Event Slides
Melbourne, Australia Global Day of Code Retreat 2018 gdcr18 - Event SlidesVictoria Schiffer
 
Accelerate Through Retrospectives (Activate Agile, Agile Australia 2018, Melb...
Accelerate Through Retrospectives (Activate Agile, Agile Australia 2018, Melb...Accelerate Through Retrospectives (Activate Agile, Agile Australia 2018, Melb...
Accelerate Through Retrospectives (Activate Agile, Agile Australia 2018, Melb...Victoria Schiffer
 
My Inspect & Adapt Life - Computershare ConneCTShe
My Inspect & Adapt Life - Computershare ConneCTSheMy Inspect & Adapt Life - Computershare ConneCTShe
My Inspect & Adapt Life - Computershare ConneCTSheVictoria Schiffer
 
The Story Mapping Game (1st Conf, Melbourne, Australia, 3rd March 2017)
The Story Mapping Game (1st Conf, Melbourne, Australia, 3rd March 2017)The Story Mapping Game (1st Conf, Melbourne, Australia, 3rd March 2017)
The Story Mapping Game (1st Conf, Melbourne, Australia, 3rd March 2017)Victoria Schiffer
 
1-1 Team Feedback (Elabor8 Lunch & Learn, Melbourne, Australia, 18th July 2016)
1-1 Team Feedback (Elabor8 Lunch & Learn, Melbourne, Australia, 18th July 2016)1-1 Team Feedback (Elabor8 Lunch & Learn, Melbourne, Australia, 18th July 2016)
1-1 Team Feedback (Elabor8 Lunch & Learn, Melbourne, Australia, 18th July 2016)Victoria Schiffer
 
Teams! Make War, Not (Only) Love! (LAST Conf 2016, Melbourne, Australia)
Teams! Make War, Not (Only) Love! (LAST Conf 2016, Melbourne, Australia)Teams! Make War, Not (Only) Love! (LAST Conf 2016, Melbourne, Australia)
Teams! Make War, Not (Only) Love! (LAST Conf 2016, Melbourne, Australia)Victoria Schiffer
 
Being Agile - The Mindset and Practices Behind Awesome Products & Software (A...
Being Agile - The Mindset and Practices Behind Awesome Products & Software (A...Being Agile - The Mindset and Practices Behind Awesome Products & Software (A...
Being Agile - The Mindset and Practices Behind Awesome Products & Software (A...Victoria Schiffer
 
Peer Groups in Agile Environments (LAST Conf 2014, Melbourne, Australia)
Peer Groups in Agile Environments (LAST Conf 2014, Melbourne, Australia)Peer Groups in Agile Environments (LAST Conf 2014, Melbourne, Australia)
Peer Groups in Agile Environments (LAST Conf 2014, Melbourne, Australia)Victoria Schiffer
 
Life Coaching in Agile Thinking (Agile Coaching Circles Meetup, September 201...
Life Coaching in Agile Thinking (Agile Coaching Circles Meetup, September 201...Life Coaching in Agile Thinking (Agile Coaching Circles Meetup, September 201...
Life Coaching in Agile Thinking (Agile Coaching Circles Meetup, September 201...Victoria Schiffer
 
Coaching for Life aka "Agile Coaching? Sure thing! What about Life Coaching i...
Coaching for Life aka "Agile Coaching? Sure thing! What about Life Coaching i...Coaching for Life aka "Agile Coaching? Sure thing! What about Life Coaching i...
Coaching for Life aka "Agile Coaching? Sure thing! What about Life Coaching i...Victoria Schiffer
 
Produkt-Innovationen gefällig? Frag deine Mitarbeiter! (SEACON 2012, Hamburg,...
Produkt-Innovationen gefällig? Frag deine Mitarbeiter! (SEACON 2012, Hamburg,...Produkt-Innovationen gefällig? Frag deine Mitarbeiter! (SEACON 2012, Hamburg,...
Produkt-Innovationen gefällig? Frag deine Mitarbeiter! (SEACON 2012, Hamburg,...Victoria Schiffer
 
Produkt-Innovationen gefällig? Frag deine Mitarbeiter! (Entwicklertag Karlsru...
Produkt-Innovationen gefällig? Frag deine Mitarbeiter! (Entwicklertag Karlsru...Produkt-Innovationen gefällig? Frag deine Mitarbeiter! (Entwicklertag Karlsru...
Produkt-Innovationen gefällig? Frag deine Mitarbeiter! (Entwicklertag Karlsru...Victoria Schiffer
 

Plus de Victoria Schiffer (14)

(Open Sourced) Cyber Scavenger Hunt - Gamified Security Awareness, even on a ...
(Open Sourced) Cyber Scavenger Hunt - Gamified Security Awareness, even on a ...(Open Sourced) Cyber Scavenger Hunt - Gamified Security Awareness, even on a ...
(Open Sourced) Cyber Scavenger Hunt - Gamified Security Awareness, even on a ...
 
(Open Sourced) Cyber Scavenger Hunt - Gamified Security Awareness, even on a ...
(Open Sourced) Cyber Scavenger Hunt - Gamified Security Awareness, even on a ...(Open Sourced) Cyber Scavenger Hunt - Gamified Security Awareness, even on a ...
(Open Sourced) Cyber Scavenger Hunt - Gamified Security Awareness, even on a ...
 
Melbourne, Australia Global Day of Code Retreat 2018 gdcr18 - Event Slides
Melbourne, Australia Global Day of Code Retreat 2018 gdcr18 - Event SlidesMelbourne, Australia Global Day of Code Retreat 2018 gdcr18 - Event Slides
Melbourne, Australia Global Day of Code Retreat 2018 gdcr18 - Event Slides
 
Accelerate Through Retrospectives (Activate Agile, Agile Australia 2018, Melb...
Accelerate Through Retrospectives (Activate Agile, Agile Australia 2018, Melb...Accelerate Through Retrospectives (Activate Agile, Agile Australia 2018, Melb...
Accelerate Through Retrospectives (Activate Agile, Agile Australia 2018, Melb...
 
My Inspect & Adapt Life - Computershare ConneCTShe
My Inspect & Adapt Life - Computershare ConneCTSheMy Inspect & Adapt Life - Computershare ConneCTShe
My Inspect & Adapt Life - Computershare ConneCTShe
 
The Story Mapping Game (1st Conf, Melbourne, Australia, 3rd March 2017)
The Story Mapping Game (1st Conf, Melbourne, Australia, 3rd March 2017)The Story Mapping Game (1st Conf, Melbourne, Australia, 3rd March 2017)
The Story Mapping Game (1st Conf, Melbourne, Australia, 3rd March 2017)
 
1-1 Team Feedback (Elabor8 Lunch & Learn, Melbourne, Australia, 18th July 2016)
1-1 Team Feedback (Elabor8 Lunch & Learn, Melbourne, Australia, 18th July 2016)1-1 Team Feedback (Elabor8 Lunch & Learn, Melbourne, Australia, 18th July 2016)
1-1 Team Feedback (Elabor8 Lunch & Learn, Melbourne, Australia, 18th July 2016)
 
Teams! Make War, Not (Only) Love! (LAST Conf 2016, Melbourne, Australia)
Teams! Make War, Not (Only) Love! (LAST Conf 2016, Melbourne, Australia)Teams! Make War, Not (Only) Love! (LAST Conf 2016, Melbourne, Australia)
Teams! Make War, Not (Only) Love! (LAST Conf 2016, Melbourne, Australia)
 
Being Agile - The Mindset and Practices Behind Awesome Products & Software (A...
Being Agile - The Mindset and Practices Behind Awesome Products & Software (A...Being Agile - The Mindset and Practices Behind Awesome Products & Software (A...
Being Agile - The Mindset and Practices Behind Awesome Products & Software (A...
 
Peer Groups in Agile Environments (LAST Conf 2014, Melbourne, Australia)
Peer Groups in Agile Environments (LAST Conf 2014, Melbourne, Australia)Peer Groups in Agile Environments (LAST Conf 2014, Melbourne, Australia)
Peer Groups in Agile Environments (LAST Conf 2014, Melbourne, Australia)
 
Life Coaching in Agile Thinking (Agile Coaching Circles Meetup, September 201...
Life Coaching in Agile Thinking (Agile Coaching Circles Meetup, September 201...Life Coaching in Agile Thinking (Agile Coaching Circles Meetup, September 201...
Life Coaching in Agile Thinking (Agile Coaching Circles Meetup, September 201...
 
Coaching for Life aka "Agile Coaching? Sure thing! What about Life Coaching i...
Coaching for Life aka "Agile Coaching? Sure thing! What about Life Coaching i...Coaching for Life aka "Agile Coaching? Sure thing! What about Life Coaching i...
Coaching for Life aka "Agile Coaching? Sure thing! What about Life Coaching i...
 
Produkt-Innovationen gefällig? Frag deine Mitarbeiter! (SEACON 2012, Hamburg,...
Produkt-Innovationen gefällig? Frag deine Mitarbeiter! (SEACON 2012, Hamburg,...Produkt-Innovationen gefällig? Frag deine Mitarbeiter! (SEACON 2012, Hamburg,...
Produkt-Innovationen gefällig? Frag deine Mitarbeiter! (SEACON 2012, Hamburg,...
 
Produkt-Innovationen gefällig? Frag deine Mitarbeiter! (Entwicklertag Karlsru...
Produkt-Innovationen gefällig? Frag deine Mitarbeiter! (Entwicklertag Karlsru...Produkt-Innovationen gefällig? Frag deine Mitarbeiter! (Entwicklertag Karlsru...
Produkt-Innovationen gefällig? Frag deine Mitarbeiter! (Entwicklertag Karlsru...
 

Dernier

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 

Dernier (20)

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

Agile Developer Immersion Workshop, LASTconf Melbourne, Australia, 19th July 2018

  • 2. Your Facilitators Dan Prager Agile Consultant @ Skillfire & ZXM @agilejitsu Victoria Schiffer Delivery Manager @ SEEK @Erdbeervogel Tomasz Janowski Technical Lead @ REA Group @janowskit
  • 4. Ice-breaker 1. Pair up and invent a groovy handshake with five distinct movements 2. Practice your handshake 3. Whip round the room and each pair does a demo
  • 5. Plan for the Day Session A: 11 am — 12:30 pm ● Welcome & Ice-breaker ● Sprint 0: Golden Master testing (Victoria) Lunch Session B: 1:30 – 3 pm ● Sprint 1: Remove Duplication & Improve Names (Dan) ● Sprint 2: Extract to Pure Functions (Tomasz) Afternoon tea Session C: 3:30 – 5 pm ● Sprint 3: Add a Feature (Tomasz) ● Sprint 4: Group Debrief
  • 6. What is Legacy Code? “Legacy Code is code without tests.”— Michael Feathers equivalently “Legacy Code is code you are afraid to change.”— J B Rainsberger Reflection: “What are some of the pros of Legacy Code?”
  • 7. Comparison to Fundamentals Immersion Similarities to Fundamentals / Regular Code Retreat ● One problem for the day ● Lots of sprints, with a different learning focus each sprint ● Pair programming, and rotate partners each sprint ● Huge focus on fast feedback through automated testing Differences ● Instead of a spec, we start with a steaming pile of legacy code ● We do not delete our code at the end of each sprint! ● Emphasis on Golden Master testing technique ● Use of TDD is now selective, BUT still highly recommended
  • 8. Sprint 0: Golden Master Testing
  • 9. Why and What of Golden Master Testing ● Why it’s hard to get started to refactor legacy code ● What Golden Master testing is and how it helps us get started with Legacy Code ● Why Build your own Golden Master infrastructure ● What about TDD and unit testing?
  • 10. Why it’s hard to get started to refactor legacy code ● Lack of tests ● ‘Fear’ of changing anything ● Low confidence in not breaking anything ● Not sure what will break, which behaviours might be impacted by the change
  • 11. "In nearly every legacy system, what the system does is more important than what it’s supposed to do.” “A characterisation test is a test that characterizes the actual behaviour of a piece of code" — Michael C. Feathers, Working Effectively with Legacy Code → It isn’t right or wrong, it simply exists Why a ‘Golden Master’?
  • 12. “A gold master test is a regression test for complex, untested systems that asserts a consistent macro-level behavior.” — Jake Worth → black box test What’s a Golden Master Test?
  • 13. “Mastering, a form of audio post production, is the process of preparing and transferring recorded audio from a source containing the final mix to a data storage device (the master); the source from which all copies will be produced. ‘Golden Master’ Analogy Mastering requires critical listening; however, software tools exist to facilitate the process. Results still depend upon the intent of the engineer, the accuracy of the speaker monitors, and the listening environment. Mastering engineers may also need to apply corrective equalization and dynamic compression in order to optimise sound translation on all playback systems. It is standard practice to make a copy of a master recording, known as a safety copy, in case the master is lost, damaged or stolen.” (Wikipedia) Golden Record: NASA
  • 14. ● Every Golden Master is unique to the specific legacy system and its behaviours ● Right level of output data captured and compared with ● Might need to scrub data (e.g. if using copy of production database in your golden master) Why Build Your Own Golden Master Infrastructure?
  • 15. What about TDD & Unit Testing? Image: Martin Fowler
  • 16. Working with Golden Master Run Code/Test Save as Golden Master Run Code/Test Capture Data/Output Compare to Golden Master Equal? 1st Run Subsequent Runs Capture Data/Output Prompts Decision: Re-Baseline Golden Master OR roll-back Keep Refactoring. No! Yes!
  • 17. Steps to building a Golden Master 1. Get the code to run 2. Randomly generate inputs, leading to plentiful output ● Fix the random number seed, leading to repeatable output 3. Capture the output of every run ● The output of the unmodified legacy system is your “Golden Master” (save it somewhere) ● Options for output capture: Roll your own “print” function and do a careful find & replace, or ○ Monkey patch “print”, or ○ Redirect stdout 4. Compare the captured output of each run to the Golden Master output ● Report success or failure → every failure prompts decision ● Report line(s) that don’t match, actual vs expected 5. Extension: Incorporate two golden-master tests in your unit test suite ● Line length of current run vs Golden Master length ● Expected empty diff (all lines match) vs Mis-matched lines
  • 18. Capturing the output (JavaScript examples) Find & Replace (41 replacements) Monkey patch console.log
  • 19. Redirecting to stdout to a file (C# example)
  • 20. Over to you! Build your own Golden Master ● Pair up! ● Get the Legacy Code in your programming language of choice http://github.com/lastconf2018/trivia ● Build your own Golden Master!
  • 21. Sprint 1: Remove Duplication & Improve Names
  • 22. Leaning on the Golden Master Focus of the Sprint 1. Find code duplications and poor-namings and fix them 2. Keep re-running the Golden Master test to confirm that you haven’t changed the system behaviour Stretch activities ● Find and fix a subtle defect in the Legacy code ● Introduce a unit test
  • 23. With Duplication def current_category(): if places[current_player] == 0: return 'Pop' if places[current_player] == 4: return 'Pop' if places[current_player] == 8: return 'Pop' if places[current_player] == 1: return 'Science' if places[current_player] == 5: return 'Science' if places[current_player] == 9: return 'Science' if places[current_player] == 2: return 'Sports' if places[current_player] == 6: return 'Sports' if places[current_player] == 10: return 'Sports' return 'Rock' Refactored def current_category(): position = places[current_player] if position in [0,4,8]: return 'Pop' if position in [1,5,9]: return 'Science' if position in [2,6,10]: return 'Sports' return 'Rock' ● Undo old cut & pastes! ● New code? “Rule of three”
  • 24. Extract code snippets to a well-named function ; This code appears in several places (duplication) ... places[current_player] = places[current_player] + roll if places[current_player] > 11: places[current_player] = places[current_player] - 12 ... def move_current_player_forward(): places[current_player] = places[current_player] + roll if places[current_player] > 11: places[current_player] = places[current_player] - 12 # the board wraps around Now we have (in a few places): ... move_current_player_forward() ...
  • 25. Kent “XP” Beck’s four rules of Simple Design Our Priorities 1. passes its tests 2. remove duplication 3. Improve names 4. Fewer functions, classes, etc.
  • 26. Sprint 2: Pure functions
  • 27. Extract to Pure Functions ● What they are ● Why they’re good: easy to unit test ● Pure functions + Commands + Glue ● Example(s) Emphasis of the sprint: 1. Start adding unit tests around your pure functions 2. Stretch: TDD your pure functions 3. Keep using the Golden Master as a back-stop
  • 28. Pure Functions A pure function is a function where the return value is only determined by its input values, without observable side effects.
  • 29. Pure Functions ● A pure function can only access what you pass it, so it’s easy to see its dependencies. ● When a function accesses some other program state, such as a global variable, it is no longer pure. ● A given invocation of a pure function can be replaced by its result. There’s no difference between “add(2,3)” and “5”. This property is called referential transparency
  • 30. Testing ● To test a pure function, you declare the values that will act as arguments and pass them to the function. The output value needs to be verified against the expected value. ● No context to set up, no current user or request ● No side effects to mock or stub ● Testing doesn’t get more straightforward than this
  • 31. Parallelization ● Pure functions can always be parallelized. ● No race conditions as there’s no shared state
  • 32. Memoization ● Pure functions always return the same output for the same input ● We only need to compute the output once for given inputs ● Caching and reusing the result is called memoization and can only be done safely with pure functions
  • 33. Examples function add(a, b) { return a + b; }
  • 34. Examples function add(a, b) { formatHdd(); return a + b; }
  • 36. Examples function doubleArray(arr) { for(let i = 0; i < arr.length; i++) { arr[i] = arr[i] * 2; } return arr; }
  • 37. Examples function rollDice() { return Math.floor(Math.random() * 6) + 1; }
  • 38. Examples function tomorrow() { const now = new Date(); return new Date(now.getTime() + (24 * 60 * 60 * 1000)); }
  • 39. Examples function tomorrow(now) { return new Date(now.getTime() + (24 * 60 * 60 * 1000)); }
  • 40. Examples function fullName(person) { person.firstName = person.firstName.trim(); person.lastName = person.firstName.trim(); return person.firstName + ' ' + person.lastName; }
  • 41. Examples function fullName(person) { return person.firstName.trim() + ' ' + person.lastName.trim(); }
  • 42. Sprint 3: Add a feature
  • 43. Add a feature (or two) Use TDD to add a new feature. Your choice of ● New question categories: History, Politics, Religion ● Support more than 6 players ● Add an optional Polish or German translation ● Invent and add a new rule Emphasis of the sprint ● Re-incorporating TDD for new features: don’t just lean on the Golden Master ● Re-baselining your Golden Master
  • 44. Sprint 4: Group discussion
  • 45. Split into two or three groups How can we apply what we have learned in the “real world” of Work? ● Where might we use Golden Master testing? ● What additional adaptations would we need? ● What about other techniques? ● Cultural issues
  • 47. Feedback forms Your honest and constructive feedback helps us to improve! — Dan, Victoria, & Tomasz
  • 48. Further learning Complementary techniques ● Github Scientist / Branch by abstraction ● Design by Contract ● Property-based testing ● Mob Programming ● etc. In-house immersions / training ● Talk to Dan! daniel.a.prager@gmail.com