101
Moving away from legacy code with BDD

Moving away from legacy code (AgileCymru)

Embed Size (px)

Citation preview

Page 1: Moving away from legacy code  (AgileCymru)

Moving away from legacy code

with BDD

Page 2: Moving away from legacy code  (AgileCymru)

BDD Practice Manager

Creator of Behat - Cucumber for PHP

Software Engineer turned Stakeholder whisperer

KonstantinKudryashov

@everzet

Page 3: Moving away from legacy code  (AgileCymru)

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

Page 4: Moving away from legacy code  (AgileCymru)

Legacy projects

Page 5: Moving away from legacy code  (AgileCymru)

How most teams see their next project

Page 6: Moving away from legacy code  (AgileCymru)

our next project

Page 7: Moving away from legacy code  (AgileCymru)

our next project

their actual next project

Page 8: Moving away from legacy code  (AgileCymru)

Agile, TDD, BDD, etc… // TODO: refactor later

Page 9: Moving away from legacy code  (AgileCymru)

Is it really that bad?

Page 10: Moving away from legacy code  (AgileCymru)

If a project can afford a salary of an engineer concerned about the project state,

then the project state is not that bad.

Page 11: Moving away from legacy code  (AgileCymru)

// TODO: refactor later

Page 12: Moving away from legacy code  (AgileCymru)

// TODO: refactor later

Page 13: Moving away from legacy code  (AgileCymru)

// TODO: refactor later

Page 14: Moving away from legacy code  (AgileCymru)

This world is full of brilliant projects that nobody is concerned about. Sadly, it’s often because

there’s no one left to care.

Page 15: Moving away from legacy code  (AgileCymru)

You deliver valueJust not as effectively as you could

Page 16: Moving away from legacy code  (AgileCymru)

Great value + Awful code = Great product yesterday

Page 17: Moving away from legacy code  (AgileCymru)

Great value + Awful code = Great product yesterday

Great value + Great code = Great product tomorrow

Page 18: Moving away from legacy code  (AgileCymru)

Great value + Awful code = Great product yesterday

Great value + Great code = Great product tomorrow

No value + Any code = Awful product anytime

Page 19: Moving away from legacy code  (AgileCymru)

Great value + Awful code = Great product yesterday

No value + Any code = Awful product anytime

Page 20: Moving away from legacy code  (AgileCymru)

Great value + Awful code = Great product yesterday

Great value + Great code = Great product tomorrow

Page 21: Moving away from legacy code  (AgileCymru)

// TODO: refactor laterAgile, TDD, BDD, etc…

Page 22: Moving away from legacy code  (AgileCymru)

Rewrite all the things!

Page 23: Moving away from legacy code  (AgileCymru)
Page 24: Moving away from legacy code  (AgileCymru)

learning

Page 25: Moving away from legacy code  (AgileCymru)

learning

trash bin

else

Page 26: Moving away from legacy code  (AgileCymru)

learning • Agile • XP • BDD

trash bin

else

Page 27: Moving away from legacy code  (AgileCymru)

learning • Agile • XP • BDD

trash bin

else

Page 28: Moving away from legacy code  (AgileCymru)

learning • Agile • XP • BDD

trash bin

else

Page 29: Moving away from legacy code  (AgileCymru)

Working system

Page 30: Moving away from legacy code  (AgileCymru)

1 year later…

Page 31: Moving away from legacy code  (AgileCymru)

nearly working system

Page 32: Moving away from legacy code  (AgileCymru)

how come?

Page 33: Moving away from legacy code  (AgileCymru)

learning • Agile • XP • BDD

trash bin

else

Page 34: Moving away from legacy code  (AgileCymru)

learning • Agile • XP • BDD

trash bin

else

Page 35: Moving away from legacy code  (AgileCymru)

legacylegacy

Page 36: Moving away from legacy code  (AgileCymru)

legacylegacy

Page 37: Moving away from legacy code  (AgileCymru)

shiny new

legacylegacy

Page 38: Moving away from legacy code  (AgileCymru)

shiny new

£Alegacylegacy

Page 39: Moving away from legacy code  (AgileCymru)

U

my features!!!

shiny new

£Alegacylegacy

Page 40: Moving away from legacy code  (AgileCymru)

shiny new

£A

U

my features!!!

legacylegacy

Page 41: Moving away from legacy code  (AgileCymru)

shiny new

£A + £B

U

my features!!!

legacylegacy

Page 42: Moving away from legacy code  (AgileCymru)

shiny new

£ U

my features!!!

£A + £B

my opportunities!!!

legacylegacy

Page 43: Moving away from legacy code  (AgileCymru)

shiny new

£ U

my features!!!

£10,000/m

£A + £B

my opportunities!!!

legacylegacy

Page 44: Moving away from legacy code  (AgileCymru)

shiny new

£ U

my features!!!

£10,000/m £10,000*x

£A + £B

my opportunities!!!

legacylegacy

Page 45: Moving away from legacy code  (AgileCymru)

shiny new

£ U

my features!!!

£A + £B

my opportunities!!!

legacylegacy

Page 46: Moving away from legacy code  (AgileCymru)

£A + £B

£ U

my features!!!

shiny new

my opportunities!!!

legacylegacy

Page 47: Moving away from legacy code  (AgileCymru)

shiny new

£A + £B + £C

my opportunities!!!

£ U

my features!!!

legacylegacy

Page 48: Moving away from legacy code  (AgileCymru)

my opportunities!!!

£

shiny new

£A + £B + £C*?

my opportunities!!!

£ U

my features!!!

legacylegacy

my opportunities!!!

£

my opportunities!!!

£

Page 49: Moving away from legacy code  (AgileCymru)

it does not work!Well, not always...

Page 50: Moving away from legacy code  (AgileCymru)

Why do legacy projects suck?

Page 51: Moving away from legacy code  (AgileCymru)

Cost

Time

cost of change

Page 52: Moving away from legacy code  (AgileCymru)

How do we balance the cost of change?

Page 53: Moving away from legacy code  (AgileCymru)

Cost

Time

cost of ownership

Page 54: Moving away from legacy code  (AgileCymru)

Cost

Time

cost of ownership

Page 55: Moving away from legacy code  (AgileCymru)

Cost

Time

cost of changecost of ownership

Page 56: Moving away from legacy code  (AgileCymru)

Cost

Time

rewrite

Page 57: Moving away from legacy code  (AgileCymru)

take ownership only when you need to support change

Page 58: Moving away from legacy code  (AgileCymru)

… Of change where?

Page 59: Moving away from legacy code  (AgileCymru)

Innovation Predictability

Page 60: Moving away from legacy code  (AgileCymru)

Innovation Predictability

Page 61: Moving away from legacy code  (AgileCymru)

Innovation Predictability

Constant change, never ideal

Rarest change, good is good enough

Page 62: Moving away from legacy code  (AgileCymru)

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?

Page 63: Moving away from legacy code  (AgileCymru)

“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

Page 64: Moving away from legacy code  (AgileCymru)

1. Where is this product going?

Impact Mapping

Page 65: Moving away from legacy code  (AgileCymru)

– 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.”

Page 66: Moving away from legacy code  (AgileCymru)

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?

Page 67: Moving away from legacy code  (AgileCymru)
Page 68: Moving away from legacy code  (AgileCymru)

MVP

Page 69: Moving away from legacy code  (AgileCymru)

Product Backlog

Page 70: Moving away from legacy code  (AgileCymru)
Page 71: Moving away from legacy code  (AgileCymru)

In order to buy more products As a customer I need to have a product autocompletion in the search field

Page 72: Moving away from legacy code  (AgileCymru)

2. Which features are going to change?

Value Prioritisation

Page 73: Moving away from legacy code  (AgileCymru)

In order to maintain my shopping history As a site visitor I need to be able to register on this site

Page 74: Moving away from legacy code  (AgileCymru)

In order to maintain my shopping history As a site visitor I need to be able to register on this site

benefit

actor

Page 75: Moving away from legacy code  (AgileCymru)

SELECT s.* FROM backlog as s ORDER BY s.role, s.benefit LIMIT 25

Page 76: Moving away from legacy code  (AgileCymru)

3. How are these features going to change?Example (3 Amigos) workshops

Page 77: Moving away from legacy code  (AgileCymru)

Three layers of a User-Story

• Business rule(s)

• Communication

• Acceptance criteria

Page 78: Moving away from legacy code  (AgileCymru)

Three layers of a User-Story

• Business rule(s)

• Communication in Examples

• Acceptance criteria

Page 79: Moving away from legacy code  (AgileCymru)

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

Page 80: Moving away from legacy code  (AgileCymru)

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

Page 81: Moving away from legacy code  (AgileCymru)

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

Page 82: Moving away from legacy code  (AgileCymru)

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

Page 83: Moving away from legacy code  (AgileCymru)

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

Page 84: Moving away from legacy code  (AgileCymru)

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

Page 85: Moving away from legacy code  (AgileCymru)

4. How to support that change?

Page 86: Moving away from legacy code  (AgileCymru)

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$

Page 87: Moving away from legacy code  (AgileCymru)

Step#1: Identify change area

Page 88: Moving away from legacy code  (AgileCymru)

Step#2: Identify old logic

Page 89: Moving away from legacy code  (AgileCymru)

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?

Page 90: Moving away from legacy code  (AgileCymru)

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

Page 91: Moving away from legacy code  (AgileCymru)

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

Page 92: Moving away from legacy code  (AgileCymru)

@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

Page 93: Moving away from legacy code  (AgileCymru)

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

Page 94: Moving away from legacy code  (AgileCymru)

Step#5: Make a change

1. Automate new scenarios

2. Make scenarios green by applying BDD loops

Page 95: Moving away from legacy code  (AgileCymru)

Stories

Examples

Describe

ImplementDesign

Page 96: Moving away from legacy code  (AgileCymru)

Working system

Page 97: Moving away from legacy code  (AgileCymru)

1 year later…

Page 98: Moving away from legacy code  (AgileCymru)

Same ashtrays, better system

Page 99: Moving away from legacy code  (AgileCymru)

Stop dreaming of a greater code

Find a way to deliver a greater value

Page 100: Moving away from legacy code  (AgileCymru)

We do that for clientsAnd help others to do it

http:// .com

Page 101: Moving away from legacy code  (AgileCymru)

Thank you!

@everzet