SlideShare a Scribd company logo
Legacy Coderetreat
About
Coderetreat started in 2009, created by:
• Gary Bernhardt
• Patrick Welsh
• Nayan Hajratwala
• Corey Haines
Legacy code retreat created in 2012 by JB
Rainsberger
Me
Adrian Bolboaca
Technical and Organizational Trainer and Coach at Mozaic Works
Why
Practice
Experiment
Learn legacy code techniques
Extend your comfort zone
Learn through pair-programing
Have fun
How
1 Day of coding
Have an existing codebase
6 pairing partners
On average 135 minutes of coding
6 different legacy code techniques
A lot of fun!
Day structure
Introduction
3 sessions in the morning
Lunch 1h
3 sessions in the afternoon
Day retrospective 30 minutes
Principles
Language agnostic
Follow the constraints of the session
Delete the code changes after each session
Focus on practice
Experiment each session
Have fun!
Prerequisites
Computer
Coding environment
Testing environment
Local source control (git, etc)
The four elements of simple design
1. Passes its tests
2. Minimizes duplication
3. Maximizes clarity
4. Has fewer elements
Basic rules of refactoring
Steps
1. Duplicate implementation
2. Cover duplicated implementation with tests
(these are learning tests)
3. Reroute original code to new code
(make sure you have some initial tests)
4. Remove old implementation
5. Check tests pass
Git
cd /myroot/myfolder
git clone https://github.com/jbrains/trivia.git
git status -> check pending changes
git commit -am "non-empty message"
git reset --hard HEAD --> reset to last commit
git clean -f -d -x -> delete all untracked files
Codebase
You can find it at https://github.com/jbrains/trivia
Use git to clone the repository
Session 1: Code reading
Take 30 minutes to read the code
Try to understand it
Work in pairs
Session 2: From nothing to system
tests
1.Find an entry point into your system, a method at
the highest level possible, closest to external calls
or the user interface
2. Define a limit of your system that blocks you
from verifying resulting behavior
3. Find a way to fake this limit so that you can
catch the results
4. Write a system test that verifies one of your
assumptions about one specific behavior of that
method
5. Refactor
Session 3: Encapsulate external
dependencies
1. Look for a method that uses an external dependency (IO, framework,
hardware, etc)
2. Isolate the real call to the external dependency from the rest of the
method logic, so that this only uses the result/value of the external call
3. Extract the real call to the external dependency into a separate method
4. Extract the method to a new class
5. Create an abstraction for the class
6. Dependency inject the abstraction by:
a. Constructor
b. Property
c. Parameter
7. Rewrite your tests so that the external dependency is:
a. stubbed
b. mocked
Lunch
1 hour
Session 4: Reveal intent
Concepts
1. Find magic number/string within the code
2. Replace the number/string with a symbolic constant which encapsulated the
value and describes the meaning of the number/string
1. Find a variable/method/class with a non-descriptive name, like Foo
2. Change Foo variable/method/class to a meaningful explicit name which
might be too long to be useful but reveals intent
3. Iteratively improve* the variable/method/class name.
Improving means:
● Shortening towards a more comfortable length
● Keeping the explicit nature of the name intact
● Staying coherent with the domain
● Avoiding duplication of concepts, i.e. synonyms for the same concept
Session 5: Refactoring conditionals
(slide 1/2)
Concepts
● Guard Clauses [1]
Is a chunk of code at the top of a function that serves
a similar purpose to a Precondition. It typically does
one (or any or all) of the following:
a. Returns an error when invalid input parameters.
b. Bails out when function call is inappropriate.
c. Handle trivial cases quickly.
● Explaining Variable [2]
Transform an expression into a temporary variable
that explains the purpose of the logical expression
Session 5: Refactoring conditionals
(slide 2/2)
Concepts
● Decompose Conditional [4]
1. Find a method that contains a conditional expression and a chunk of
functionality within this conditional
2. Use extract method to move the real functionality into a separate method
● Consolidate Conditional Expression [5]
1. Find a method that contains multiple conditional expressions or a
composite conditional
2. Use extract method to move all of the conditional logic into a separate
method so that it combines all the conditional logic
3. Give the new method a descriptive name that you can use in the
original method (like an explaining variable)
Session 6: Extract pure functions
A pure function always evaluates the same result value given the same argument
value(s). Its result cannot depend on any hidden information or state that may change
as program execution proceeds or between different executions of the program. *
Steps
1. Find an atomic piece of code that can be moved into a separate public function
by using Extract method
2. Replace all external dependencies within this function with independent or primitive
parameters
a. Constants
b. Class variables
c. Global variables
d. Method variables outside of the extracted code
3. Returns an object instantiated inside the function
4. Add tests for the method
a. At least one test for each parameter
b. One test for each value range of each parameter
5. Refactor
Closing circle
1)How did you feel
2)What did you learn
3)What would you apply Monday?
Contact me
Remote pair-programming
Unit testing workshop
Test driven development workshop
Refactoring workshop
Working FAST and safe with existing code workshop
Code retreat workshop
http://mozaicworks.com
adrian.bolboaca@mozaicworks.com
@adibolb
blog.adrianbolboaca.ro

More Related Content

What's hot

Refactoring: Improve the design of existing code
Refactoring: Improve the design of existing codeRefactoring: Improve the design of existing code
Refactoring: Improve the design of existing codeValerio Maggio
 
Dynamic analysis in Software Testing
Dynamic analysis in Software TestingDynamic analysis in Software Testing
Dynamic analysis in Software TestingSagar Pednekar
 
Bad Code Smells
Bad Code SmellsBad Code Smells
Bad Code Smellskim.mens
 
Boundary and equivalnce systematic test design
Boundary and equivalnce   systematic test designBoundary and equivalnce   systematic test design
Boundary and equivalnce systematic test designIan McDonald
 
Whitebox testing
Whitebox testingWhitebox testing
Whitebox testingOana Feidi
 
Input Space Partitioning
Input Space PartitioningInput Space Partitioning
Input Space PartitioningRiyad Parvez
 
Magic Literals In Pharo
 Magic Literals In Pharo Magic Literals In Pharo
Magic Literals In PharoESUG
 
Class 4: Making Procedures
Class 4: Making ProceduresClass 4: Making Procedures
Class 4: Making ProceduresDavid Evans
 
White Box Testing
White Box TestingWhite Box Testing
White Box TestingAlisha Roy
 
SE2_Lec 21_ TDD and Junit
SE2_Lec 21_ TDD and JunitSE2_Lec 21_ TDD and Junit
SE2_Lec 21_ TDD and JunitAmr E. Mohamed
 
Software Testing Techniques
Software Testing TechniquesSoftware Testing Techniques
Software Testing TechniquesKiran Kumar
 
Test driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseTest driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseUTC Fire & Security
 
White Box testing by Pankaj Thakur, NITTTR Chandigarh
White Box testing by Pankaj Thakur, NITTTR ChandigarhWhite Box testing by Pankaj Thakur, NITTTR Chandigarh
White Box testing by Pankaj Thakur, NITTTR ChandigarhPankaj Thakur
 
Testing Fundamentals
Testing FundamentalsTesting Fundamentals
Testing FundamentalsKiran Kumar
 
Coding and testing In Software Engineering
Coding and testing In Software EngineeringCoding and testing In Software Engineering
Coding and testing In Software EngineeringSatya Bhushan Verma
 
Mutation Testing and MuJava
Mutation Testing and MuJavaMutation Testing and MuJava
Mutation Testing and MuJavaKrunal Parmar
 

What's hot (20)

Refactoring: Improve the design of existing code
Refactoring: Improve the design of existing codeRefactoring: Improve the design of existing code
Refactoring: Improve the design of existing code
 
Dynamic analysis in Software Testing
Dynamic analysis in Software TestingDynamic analysis in Software Testing
Dynamic analysis in Software Testing
 
Bad Code Smells
Bad Code SmellsBad Code Smells
Bad Code Smells
 
Boundary and equivalnce systematic test design
Boundary and equivalnce   systematic test designBoundary and equivalnce   systematic test design
Boundary and equivalnce systematic test design
 
Whitebox testing
Whitebox testingWhitebox testing
Whitebox testing
 
Input Space Partitioning
Input Space PartitioningInput Space Partitioning
Input Space Partitioning
 
Magic Literals In Pharo
 Magic Literals In Pharo Magic Literals In Pharo
Magic Literals In Pharo
 
Class 4: Making Procedures
Class 4: Making ProceduresClass 4: Making Procedures
Class 4: Making Procedures
 
White Box Testing
White Box TestingWhite Box Testing
White Box Testing
 
SE2_Lec 21_ TDD and Junit
SE2_Lec 21_ TDD and JunitSE2_Lec 21_ TDD and Junit
SE2_Lec 21_ TDD and Junit
 
Whitebox
WhiteboxWhitebox
Whitebox
 
Software Testing Techniques
Software Testing TechniquesSoftware Testing Techniques
Software Testing Techniques
 
Test driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseTest driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + Eclipse
 
Black Box Testing
Black Box TestingBlack Box Testing
Black Box Testing
 
White Box testing by Pankaj Thakur, NITTTR Chandigarh
White Box testing by Pankaj Thakur, NITTTR ChandigarhWhite Box testing by Pankaj Thakur, NITTTR Chandigarh
White Box testing by Pankaj Thakur, NITTTR Chandigarh
 
Testing Fundamentals
Testing FundamentalsTesting Fundamentals
Testing Fundamentals
 
Coding and testing In Software Engineering
Coding and testing In Software EngineeringCoding and testing In Software Engineering
Coding and testing In Software Engineering
 
Sta unit 4(abimanyu)
Sta unit 4(abimanyu)Sta unit 4(abimanyu)
Sta unit 4(abimanyu)
 
White box testing
White box testingWhite box testing
White box testing
 
Mutation Testing and MuJava
Mutation Testing and MuJavaMutation Testing and MuJava
Mutation Testing and MuJava
 

Similar to Legacy Coderetreat @Budapest 2013 02 16

Bye Bye Cowboy Coder Days! (Legacy Code & TDD)
Bye Bye Cowboy Coder Days! (Legacy Code & TDD)Bye Bye Cowboy Coder Days! (Legacy Code & TDD)
Bye Bye Cowboy Coder Days! (Legacy Code & TDD)Kaunas Java User Group
 
Agile korea 2013 유석문
Agile korea 2013 유석문Agile korea 2013 유석문
Agile korea 2013 유석문Sangcheol Hwang
 
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...DevDay.org
 
Testing the untestable
Testing the untestableTesting the untestable
Testing the untestableRoyKlein
 
Object Oriented Programming Lab Manual
Object Oriented Programming Lab Manual Object Oriented Programming Lab Manual
Object Oriented Programming Lab Manual Abdul Hannan
 
The programming philosophy of jrql
The programming philosophy of jrqlThe programming philosophy of jrql
The programming philosophy of jrqlmsg systems ag
 
Unit Testing Full@
Unit Testing Full@Unit Testing Full@
Unit Testing Full@Alex Borsuk
 
Getting Started with Test-Driven Development at Longhorn PHP 2023
Getting Started with Test-Driven Development at Longhorn PHP 2023Getting Started with Test-Driven Development at Longhorn PHP 2023
Getting Started with Test-Driven Development at Longhorn PHP 2023Scott Keck-Warren
 
Mca2030 object oriented programming – c++
Mca2030  object oriented programming – c++Mca2030  object oriented programming – c++
Mca2030 object oriented programming – c++smumbahelp
 
The Ring programming language version 1.8 book - Part 81 of 202
The Ring programming language version 1.8 book - Part 81 of 202The Ring programming language version 1.8 book - Part 81 of 202
The Ring programming language version 1.8 book - Part 81 of 202Mahmoud Samir Fayed
 
Ddc2011 효과적으로레거시코드다루기
Ddc2011 효과적으로레거시코드다루기Ddc2011 효과적으로레거시코드다루기
Ddc2011 효과적으로레거시코드다루기Myeongseok Baek
 
types of testing with descriptions and examples
types of testing with descriptions and examplestypes of testing with descriptions and examples
types of testing with descriptions and examplesMani Deepak Choudhry
 
Refactoring_Rosenheim_2008_Workshop
Refactoring_Rosenheim_2008_WorkshopRefactoring_Rosenheim_2008_Workshop
Refactoring_Rosenheim_2008_WorkshopMax Kleiner
 
Refactoring Techniques
Refactoring TechniquesRefactoring Techniques
Refactoring TechniquesMayada Ghanem
 
Hadoop testing workshop - july 2013
Hadoop testing workshop - july 2013Hadoop testing workshop - july 2013
Hadoop testing workshop - july 2013Ophir Cohen
 
Testing, a pragmatic approach
Testing, a pragmatic approachTesting, a pragmatic approach
Testing, a pragmatic approachEnrico Da Ros
 
Java căn bản - Chapter7
Java căn bản - Chapter7Java căn bản - Chapter7
Java căn bản - Chapter7Vince Vo
 

Similar to Legacy Coderetreat @Budapest 2013 02 16 (20)

Bye Bye Cowboy Coder Days! (Legacy Code & TDD)
Bye Bye Cowboy Coder Days! (Legacy Code & TDD)Bye Bye Cowboy Coder Days! (Legacy Code & TDD)
Bye Bye Cowboy Coder Days! (Legacy Code & TDD)
 
Agile korea 2013 유석문
Agile korea 2013 유석문Agile korea 2013 유석문
Agile korea 2013 유석문
 
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
 
OOPSCA1.pptx
OOPSCA1.pptxOOPSCA1.pptx
OOPSCA1.pptx
 
Testing the untestable
Testing the untestableTesting the untestable
Testing the untestable
 
Object Oriented Programming Lab Manual
Object Oriented Programming Lab Manual Object Oriented Programming Lab Manual
Object Oriented Programming Lab Manual
 
The programming philosophy of jrql
The programming philosophy of jrqlThe programming philosophy of jrql
The programming philosophy of jrql
 
Unit Testing Full@
Unit Testing Full@Unit Testing Full@
Unit Testing Full@
 
Getting Started with Test-Driven Development at Longhorn PHP 2023
Getting Started with Test-Driven Development at Longhorn PHP 2023Getting Started with Test-Driven Development at Longhorn PHP 2023
Getting Started with Test-Driven Development at Longhorn PHP 2023
 
Mca2030 object oriented programming – c++
Mca2030  object oriented programming – c++Mca2030  object oriented programming – c++
Mca2030 object oriented programming – c++
 
The Ring programming language version 1.8 book - Part 81 of 202
The Ring programming language version 1.8 book - Part 81 of 202The Ring programming language version 1.8 book - Part 81 of 202
The Ring programming language version 1.8 book - Part 81 of 202
 
Ddc2011 효과적으로레거시코드다루기
Ddc2011 효과적으로레거시코드다루기Ddc2011 효과적으로레거시코드다루기
Ddc2011 효과적으로레거시코드다루기
 
Chapter 3
Chapter 3Chapter 3
Chapter 3
 
types of testing with descriptions and examples
types of testing with descriptions and examplestypes of testing with descriptions and examples
types of testing with descriptions and examples
 
Refactoring_Rosenheim_2008_Workshop
Refactoring_Rosenheim_2008_WorkshopRefactoring_Rosenheim_2008_Workshop
Refactoring_Rosenheim_2008_Workshop
 
Bad Smell In Codes 1
Bad Smell In Codes 1Bad Smell In Codes 1
Bad Smell In Codes 1
 
Refactoring Techniques
Refactoring TechniquesRefactoring Techniques
Refactoring Techniques
 
Hadoop testing workshop - july 2013
Hadoop testing workshop - july 2013Hadoop testing workshop - july 2013
Hadoop testing workshop - july 2013
 
Testing, a pragmatic approach
Testing, a pragmatic approachTesting, a pragmatic approach
Testing, a pragmatic approach
 
Java căn bản - Chapter7
Java căn bản - Chapter7Java căn bản - Chapter7
Java căn bản - Chapter7
 

More from Adi Bolboaca

Evolutionary Design - NewCrafts Paris 18 May 2018
Evolutionary Design - NewCrafts Paris 18 May 2018Evolutionary Design - NewCrafts Paris 18 May 2018
Evolutionary Design - NewCrafts Paris 18 May 2018Adi Bolboaca
 
Stop Task Switching
Stop Task SwitchingStop Task Switching
Stop Task SwitchingAdi Bolboaca
 
Evolutionary Design: Take Only One Decision at a Time
Evolutionary Design: Take Only One Decision at a TimeEvolutionary Design: Take Only One Decision at a Time
Evolutionary Design: Take Only One Decision at a TimeAdi Bolboaca
 
Evolutionary Design - Refactoring Heuristics
Evolutionary Design - Refactoring HeuristicsEvolutionary Design - Refactoring Heuristics
Evolutionary Design - Refactoring HeuristicsAdi Bolboaca
 
Behind Agile Practices
Behind Agile PracticesBehind Agile Practices
Behind Agile PracticesAdi Bolboaca
 
Architecture for Disaster Resistant Systems @I TAKE Unconference 29 05 2015
Architecture for Disaster Resistant Systems @I TAKE Unconference 29 05 2015Architecture for Disaster Resistant Systems @I TAKE Unconference 29 05 2015
Architecture for Disaster Resistant Systems @I TAKE Unconference 29 05 2015Adi Bolboaca
 
Coderetreat @AgileFinland Turku 2014 11 15
 Coderetreat @AgileFinland Turku 2014 11 15 Coderetreat @AgileFinland Turku 2014 11 15
Coderetreat @AgileFinland Turku 2014 11 15Adi Bolboaca
 
Coderetreat @AgileFinland Helsinki 2014 11 13
Coderetreat @AgileFinland Helsinki 2014 11 13Coderetreat @AgileFinland Helsinki 2014 11 13
Coderetreat @AgileFinland Helsinki 2014 11 13Adi Bolboaca
 
Coderetreat @AgileFinland Tampere 2014 11 12
Coderetreat @AgileFinland Tampere 2014 11 12Coderetreat @AgileFinland Tampere 2014 11 12
Coderetreat @AgileFinland Tampere 2014 11 12Adi Bolboaca
 
Refactoring Dojo @AgileWorks Bucharest 21 May 2014
Refactoring Dojo @AgileWorks Bucharest 21 May 2014Refactoring Dojo @AgileWorks Bucharest 21 May 2014
Refactoring Dojo @AgileWorks Bucharest 21 May 2014Adi Bolboaca
 
Sherlock Holmes and Pairing @Romanian Testing Conference 2014 05 15
Sherlock Holmes and Pairing @Romanian Testing Conference 2014 05 15Sherlock Holmes and Pairing @Romanian Testing Conference 2014 05 15
Sherlock Holmes and Pairing @Romanian Testing Conference 2014 05 15Adi Bolboaca
 
TDD Mini Workshop @ Bucharest JUG 2014 04 24
TDD Mini Workshop @ Bucharest JUG 2014 04 24TDD Mini Workshop @ Bucharest JUG 2014 04 24
TDD Mini Workshop @ Bucharest JUG 2014 04 24Adi Bolboaca
 
Coderetreat Slides on the Global Day of Coderetreat, Bucharest, December 2013
Coderetreat Slides on the Global Day of Coderetreat, Bucharest, December 2013Coderetreat Slides on the Global Day of Coderetreat, Bucharest, December 2013
Coderetreat Slides on the Global Day of Coderetreat, Bucharest, December 2013Adi Bolboaca
 
Sherlock Holmes and Pairing @Bucharest JUG 2013 11 21
Sherlock Holmes and Pairing @Bucharest JUG 2013 11 21Sherlock Holmes and Pairing @Bucharest JUG 2013 11 21
Sherlock Holmes and Pairing @Bucharest JUG 2013 11 21Adi Bolboaca
 
Sherlock Holmes and Pairing @Wlidcard Conference 2013 09 13
Sherlock Holmes and Pairing @Wlidcard Conference 2013 09 13Sherlock Holmes and Pairing @Wlidcard Conference 2013 09 13
Sherlock Holmes and Pairing @Wlidcard Conference 2013 09 13Adi Bolboaca
 
Code retreat @AgileWorks Bucharest 7 September 2013
Code retreat @AgileWorks Bucharest 7 September 2013Code retreat @AgileWorks Bucharest 7 September 2013
Code retreat @AgileWorks Bucharest 7 September 2013Adi Bolboaca
 
Coderetreat @AgileWorks Bucharest 2012 07 06
Coderetreat @AgileWorks Bucharest 2012 07 06 Coderetreat @AgileWorks Bucharest 2012 07 06
Coderetreat @AgileWorks Bucharest 2012 07 06 Adi Bolboaca
 
Coderetreat @Sofia 2012 10 27
Coderetreat @Sofia 2012 10 27Coderetreat @Sofia 2012 10 27
Coderetreat @Sofia 2012 10 27Adi Bolboaca
 
Coderetreat @Turku 2012 10 20
Coderetreat @Turku 2012 10 20 Coderetreat @Turku 2012 10 20
Coderetreat @Turku 2012 10 20 Adi Bolboaca
 
Coderetreat @Sibiu 2012 08 18
Coderetreat @Sibiu 2012 08 18Coderetreat @Sibiu 2012 08 18
Coderetreat @Sibiu 2012 08 18Adi Bolboaca
 

More from Adi Bolboaca (20)

Evolutionary Design - NewCrafts Paris 18 May 2018
Evolutionary Design - NewCrafts Paris 18 May 2018Evolutionary Design - NewCrafts Paris 18 May 2018
Evolutionary Design - NewCrafts Paris 18 May 2018
 
Stop Task Switching
Stop Task SwitchingStop Task Switching
Stop Task Switching
 
Evolutionary Design: Take Only One Decision at a Time
Evolutionary Design: Take Only One Decision at a TimeEvolutionary Design: Take Only One Decision at a Time
Evolutionary Design: Take Only One Decision at a Time
 
Evolutionary Design - Refactoring Heuristics
Evolutionary Design - Refactoring HeuristicsEvolutionary Design - Refactoring Heuristics
Evolutionary Design - Refactoring Heuristics
 
Behind Agile Practices
Behind Agile PracticesBehind Agile Practices
Behind Agile Practices
 
Architecture for Disaster Resistant Systems @I TAKE Unconference 29 05 2015
Architecture for Disaster Resistant Systems @I TAKE Unconference 29 05 2015Architecture for Disaster Resistant Systems @I TAKE Unconference 29 05 2015
Architecture for Disaster Resistant Systems @I TAKE Unconference 29 05 2015
 
Coderetreat @AgileFinland Turku 2014 11 15
 Coderetreat @AgileFinland Turku 2014 11 15 Coderetreat @AgileFinland Turku 2014 11 15
Coderetreat @AgileFinland Turku 2014 11 15
 
Coderetreat @AgileFinland Helsinki 2014 11 13
Coderetreat @AgileFinland Helsinki 2014 11 13Coderetreat @AgileFinland Helsinki 2014 11 13
Coderetreat @AgileFinland Helsinki 2014 11 13
 
Coderetreat @AgileFinland Tampere 2014 11 12
Coderetreat @AgileFinland Tampere 2014 11 12Coderetreat @AgileFinland Tampere 2014 11 12
Coderetreat @AgileFinland Tampere 2014 11 12
 
Refactoring Dojo @AgileWorks Bucharest 21 May 2014
Refactoring Dojo @AgileWorks Bucharest 21 May 2014Refactoring Dojo @AgileWorks Bucharest 21 May 2014
Refactoring Dojo @AgileWorks Bucharest 21 May 2014
 
Sherlock Holmes and Pairing @Romanian Testing Conference 2014 05 15
Sherlock Holmes and Pairing @Romanian Testing Conference 2014 05 15Sherlock Holmes and Pairing @Romanian Testing Conference 2014 05 15
Sherlock Holmes and Pairing @Romanian Testing Conference 2014 05 15
 
TDD Mini Workshop @ Bucharest JUG 2014 04 24
TDD Mini Workshop @ Bucharest JUG 2014 04 24TDD Mini Workshop @ Bucharest JUG 2014 04 24
TDD Mini Workshop @ Bucharest JUG 2014 04 24
 
Coderetreat Slides on the Global Day of Coderetreat, Bucharest, December 2013
Coderetreat Slides on the Global Day of Coderetreat, Bucharest, December 2013Coderetreat Slides on the Global Day of Coderetreat, Bucharest, December 2013
Coderetreat Slides on the Global Day of Coderetreat, Bucharest, December 2013
 
Sherlock Holmes and Pairing @Bucharest JUG 2013 11 21
Sherlock Holmes and Pairing @Bucharest JUG 2013 11 21Sherlock Holmes and Pairing @Bucharest JUG 2013 11 21
Sherlock Holmes and Pairing @Bucharest JUG 2013 11 21
 
Sherlock Holmes and Pairing @Wlidcard Conference 2013 09 13
Sherlock Holmes and Pairing @Wlidcard Conference 2013 09 13Sherlock Holmes and Pairing @Wlidcard Conference 2013 09 13
Sherlock Holmes and Pairing @Wlidcard Conference 2013 09 13
 
Code retreat @AgileWorks Bucharest 7 September 2013
Code retreat @AgileWorks Bucharest 7 September 2013Code retreat @AgileWorks Bucharest 7 September 2013
Code retreat @AgileWorks Bucharest 7 September 2013
 
Coderetreat @AgileWorks Bucharest 2012 07 06
Coderetreat @AgileWorks Bucharest 2012 07 06 Coderetreat @AgileWorks Bucharest 2012 07 06
Coderetreat @AgileWorks Bucharest 2012 07 06
 
Coderetreat @Sofia 2012 10 27
Coderetreat @Sofia 2012 10 27Coderetreat @Sofia 2012 10 27
Coderetreat @Sofia 2012 10 27
 
Coderetreat @Turku 2012 10 20
Coderetreat @Turku 2012 10 20 Coderetreat @Turku 2012 10 20
Coderetreat @Turku 2012 10 20
 
Coderetreat @Sibiu 2012 08 18
Coderetreat @Sibiu 2012 08 18Coderetreat @Sibiu 2012 08 18
Coderetreat @Sibiu 2012 08 18
 

Recently uploaded

Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonDianaGray10
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...CzechDreamin
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Julian Hyde
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfCheryl Hung
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...CzechDreamin
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomCzechDreamin
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlPeter Udo Diehl
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backElena Simperl
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...Product School
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Tobias Schneck
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCzechDreamin
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyJohn Staveley
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka DoktorováCzechDreamin
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2DianaGray10
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...CzechDreamin
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekCzechDreamin
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupCatarinaPereira64715
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...Product School
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor TurskyiFwdays
 

Recently uploaded (20)

Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 

Legacy Coderetreat @Budapest 2013 02 16

  • 2. About Coderetreat started in 2009, created by: • Gary Bernhardt • Patrick Welsh • Nayan Hajratwala • Corey Haines Legacy code retreat created in 2012 by JB Rainsberger
  • 3. Me Adrian Bolboaca Technical and Organizational Trainer and Coach at Mozaic Works
  • 4. Why Practice Experiment Learn legacy code techniques Extend your comfort zone Learn through pair-programing Have fun
  • 5. How 1 Day of coding Have an existing codebase 6 pairing partners On average 135 minutes of coding 6 different legacy code techniques A lot of fun!
  • 6. Day structure Introduction 3 sessions in the morning Lunch 1h 3 sessions in the afternoon Day retrospective 30 minutes
  • 7. Principles Language agnostic Follow the constraints of the session Delete the code changes after each session Focus on practice Experiment each session Have fun!
  • 9. The four elements of simple design 1. Passes its tests 2. Minimizes duplication 3. Maximizes clarity 4. Has fewer elements
  • 10. Basic rules of refactoring Steps 1. Duplicate implementation 2. Cover duplicated implementation with tests (these are learning tests) 3. Reroute original code to new code (make sure you have some initial tests) 4. Remove old implementation 5. Check tests pass
  • 11. Git cd /myroot/myfolder git clone https://github.com/jbrains/trivia.git git status -> check pending changes git commit -am "non-empty message" git reset --hard HEAD --> reset to last commit git clean -f -d -x -> delete all untracked files
  • 12. Codebase You can find it at https://github.com/jbrains/trivia Use git to clone the repository
  • 13. Session 1: Code reading Take 30 minutes to read the code Try to understand it Work in pairs
  • 14. Session 2: From nothing to system tests 1.Find an entry point into your system, a method at the highest level possible, closest to external calls or the user interface 2. Define a limit of your system that blocks you from verifying resulting behavior 3. Find a way to fake this limit so that you can catch the results 4. Write a system test that verifies one of your assumptions about one specific behavior of that method 5. Refactor
  • 15. Session 3: Encapsulate external dependencies 1. Look for a method that uses an external dependency (IO, framework, hardware, etc) 2. Isolate the real call to the external dependency from the rest of the method logic, so that this only uses the result/value of the external call 3. Extract the real call to the external dependency into a separate method 4. Extract the method to a new class 5. Create an abstraction for the class 6. Dependency inject the abstraction by: a. Constructor b. Property c. Parameter 7. Rewrite your tests so that the external dependency is: a. stubbed b. mocked
  • 17. Session 4: Reveal intent Concepts 1. Find magic number/string within the code 2. Replace the number/string with a symbolic constant which encapsulated the value and describes the meaning of the number/string 1. Find a variable/method/class with a non-descriptive name, like Foo 2. Change Foo variable/method/class to a meaningful explicit name which might be too long to be useful but reveals intent 3. Iteratively improve* the variable/method/class name. Improving means: ● Shortening towards a more comfortable length ● Keeping the explicit nature of the name intact ● Staying coherent with the domain ● Avoiding duplication of concepts, i.e. synonyms for the same concept
  • 18. Session 5: Refactoring conditionals (slide 1/2) Concepts ● Guard Clauses [1] Is a chunk of code at the top of a function that serves a similar purpose to a Precondition. It typically does one (or any or all) of the following: a. Returns an error when invalid input parameters. b. Bails out when function call is inappropriate. c. Handle trivial cases quickly. ● Explaining Variable [2] Transform an expression into a temporary variable that explains the purpose of the logical expression
  • 19. Session 5: Refactoring conditionals (slide 2/2) Concepts ● Decompose Conditional [4] 1. Find a method that contains a conditional expression and a chunk of functionality within this conditional 2. Use extract method to move the real functionality into a separate method ● Consolidate Conditional Expression [5] 1. Find a method that contains multiple conditional expressions or a composite conditional 2. Use extract method to move all of the conditional logic into a separate method so that it combines all the conditional logic 3. Give the new method a descriptive name that you can use in the original method (like an explaining variable)
  • 20. Session 6: Extract pure functions A pure function always evaluates the same result value given the same argument value(s). Its result cannot depend on any hidden information or state that may change as program execution proceeds or between different executions of the program. * Steps 1. Find an atomic piece of code that can be moved into a separate public function by using Extract method 2. Replace all external dependencies within this function with independent or primitive parameters a. Constants b. Class variables c. Global variables d. Method variables outside of the extracted code 3. Returns an object instantiated inside the function 4. Add tests for the method a. At least one test for each parameter b. One test for each value range of each parameter 5. Refactor
  • 21. Closing circle 1)How did you feel 2)What did you learn 3)What would you apply Monday?
  • 22. Contact me Remote pair-programming Unit testing workshop Test driven development workshop Refactoring workshop Working FAST and safe with existing code workshop Code retreat workshop http://mozaicworks.com adrian.bolboaca@mozaicworks.com @adibolb blog.adrianbolboaca.ro