moving away from legacy code (agilecymru)
TRANSCRIPT
Moving away from legacy code
with BDD
BDD Practice Manager
Creator of Behat - Cucumber for PHP
Software Engineer turned Stakeholder whisperer
KonstantinKudryashov
@everzet
This talk is about
• Solving purely technical “TCIAM” problem using behaviour driven development practices and agile discovery processes
• Planning a delivery strategy on the basis of change appreciation
• Real-life experience
Legacy projects
How most teams see their next project
our next project
our next project
their actual next project
Agile, TDD, BDD, etc… // TODO: refactor later
Is it really that bad?
If a project can afford a salary of an engineer concerned about the project state,
then the project state is not that bad.
// TODO: refactor later
// TODO: refactor later
// TODO: refactor later
This world is full of brilliant projects that nobody is concerned about. Sadly, it’s often because
there’s no one left to care.
You deliver valueJust not as effectively as you could
Great value + Awful code = Great product yesterday
Great value + Awful code = Great product yesterday
Great value + Great code = Great product tomorrow
Great value + Awful code = Great product yesterday
Great value + Great code = Great product tomorrow
No value + Any code = Awful product anytime
Great value + Awful code = Great product yesterday
No value + Any code = Awful product anytime
Great value + Awful code = Great product yesterday
Great value + Great code = Great product tomorrow
// TODO: refactor laterAgile, TDD, BDD, etc…
Rewrite all the things!
learning
learning
trash bin
else
learning • Agile • XP • BDD
trash bin
else
learning • Agile • XP • BDD
trash bin
else
learning • Agile • XP • BDD
trash bin
else
Working system
1 year later…
nearly working system
how come?
learning • Agile • XP • BDD
trash bin
else
learning • Agile • XP • BDD
trash bin
else
legacylegacy
legacylegacy
shiny new
legacylegacy
shiny new
£Alegacylegacy
U
my features!!!
shiny new
£Alegacylegacy
shiny new
£A
U
my features!!!
legacylegacy
shiny new
£A + £B
U
my features!!!
legacylegacy
shiny new
£ U
my features!!!
£A + £B
my opportunities!!!
legacylegacy
shiny new
£ U
my features!!!
£10,000/m
£A + £B
my opportunities!!!
legacylegacy
shiny new
£ U
my features!!!
£10,000/m £10,000*x
£A + £B
my opportunities!!!
legacylegacy
shiny new
£ U
my features!!!
£A + £B
my opportunities!!!
legacylegacy
£A + £B
£ U
my features!!!
shiny new
my opportunities!!!
legacylegacy
shiny new
£A + £B + £C
my opportunities!!!
£ U
my features!!!
legacylegacy
my opportunities!!!
£
shiny new
£A + £B + £C*?
my opportunities!!!
£ U
my features!!!
legacylegacy
my opportunities!!!
£
my opportunities!!!
£
it does not work!Well, not always...
Why do legacy projects suck?
Cost
Time
cost of change
How do we balance the cost of change?
Cost
Time
cost of ownership
Cost
Time
cost of ownership
Cost
Time
cost of changecost of ownership
Cost
Time
rewrite
take ownership only when you need to support change
… Of change where?
Innovation Predictability
Innovation Predictability
Innovation Predictability
Constant change, never ideal
Rarest change, good is good enough
Questionnaire
1. Where is this product going?
2. Which features need to change?
3. How are they going to change?
4. How to support that change?
“BDD Pipeline”
1. Where is this product going?
2. Which features need to change?
3. How are they going to change?
4. How to support that change?
• Impact Mapping
• Value Prioritisation
• Example (3 Amigos) Workshop
• BDD layers
1. Where is this product going?
Impact Mapping
– Gojko Adzic
“Impact mapping is a strategic planning technique that prevents organisations from getting lost
while building products and delivering projects, by clearly communicating assumptions, helping teams align their activities with overall business objectives and make better roadmap decisions.”
Four levels of Impact Map
1. Why? are we doing all this (rewrite)? What is the goal we’re trying to achieve?
2. Who? will be impacted by it?
3. How? can they help us to achieve the goal?
4. What? can we do to support them?
MVP
Product Backlog
In order to buy more products As a customer I need to have a product autocompletion in the search field
2. Which features are going to change?
Value Prioritisation
In order to maintain my shopping history As a site visitor I need to be able to register on this site
In order to maintain my shopping history As a site visitor I need to be able to register on this site
benefit
actor
SELECT s.* FROM backlog as s ORDER BY s.role, s.benefit LIMIT 25
3. How are these features going to change?Example (3 Amigos) workshops
Three layers of a User-Story
• Business rule(s)
• Communication
• Acceptance criteria
Three layers of a User-Story
• Business rule(s)
• Communication in Examples
• Acceptance criteria
In order to keep track of stock As a store owner I want to add items back to stock when they are returned
Feature: Returned items go back to stock
Scenario: Refunded items should be returned to stock
In order to keep track of stock As a store owner I want to add items back to stock when they are returned
Feature: Returned items go back to stock
Scenario: Replaced items should be returned to stock
Scenario: Refunded items should be returned to stock
In order to keep track of stock As a store owner I want to add items back to stock when they are returned
Feature: Returned items go back to stock
Scenario: ...
Scenario: Replaced items should be returned to stock
Scenario: Refunded items should be returned to stock
In order to keep track of stock As a store owner I want to add items back to stock when they are returned
Feature: Returned items go back to stock
Scenario: ...
Scenario: ...
Scenario: ...
Scenario: ...
Scenario: ...
Scenario: Replaced items should be returned to stock
Scenario: Refunded items should be returned to stock
In order to keep track of stock As a store owner I want to add items back to stock when they are returned
Feature: Returned items go back to stock
Given a customer previously bought a black sweater from us And we currently have three black sweaters left in stock When customer returns the sweater for a refund Then we should have four black sweaters in stock
Scenario: Refunded items should be returned to stock
In order to keep track of stock As a store owner I want to add items back to stock when they are returned
Feature: Returned items go back to stock
4. How to support that change?
Scenario: Refunded items should be returned to stock
In order to keep track of stock As a store owner I want to add items back to stock when they are returned
Feature: Returned items go back to stock
Given a customer previously bought a black sweater costing 15$ from us And we currently have three black sweaters left in stock When customer returns the sweater for a refund Then we should have four black sweaters in stock And customer account should be debited with 15$
Step#1: Identify change area
Step#2: Identify old logic
Step#3: Discuss old logic
1. What should this thing do
2. What if it suddenly stops doing it?
3. How would you know if it doesn't work?
4. How would you know if it does?
Scenario: Replaced items should be returned to stock
Scenario: Refunded items should be returned to stock
In order to keep track of stock As a store owner I want to add items back to stock when they are returned
Feature: Returned items go back to stock
Scenario: Cost of refunded item should be returned to customer bank account
Scenario: Cost of refunded item should be returned to customer PayPal account
Scenario: Cost of refunded item should be returned to customer via in-shop credits
Scenario: Replaced items should be returned to stock
Scenario: Refunded items should be returned to stock
In order to keep track of stock As a store owner I want to add items back to stock when they are returned
Feature: Returned items go back to stock
@legacy Scenario: Cost of refunded item should be returned to customer bank account
@legacy Scenario: Cost of refunded item should be returned to customer PayPal account
@legacy Scenario: Cost of refunded item should be returned to customer via in-shop credits
Scenario: Replaced items should be returned to stock
Scenario: Refunded items should be returned to stock
In order to keep track of stock As a store owner I want to add items back to stock when they are returned
Feature: Returned items go back to stock
Step#4: Prepare for A change
1. Cover old behaviour in an end-to-end fashion
2. Make sure that scenarios/tests are green
3. Refactor code to make the lower testing possible
4. Convert scenarios/tests to lower level tests
Step#5: Make a change
1. Automate new scenarios
2. Make scenarios green by applying BDD loops
Stories
Examples
Describe
ImplementDesign
Working system
1 year later…
Same ashtrays, better system
Stop dreaming of a greater code
Find a way to deliver a greater value
We do that for clientsAnd help others to do it
http:// .com
Thank you!
@everzet