Top Banner
Moving away from legacy code with BDD
88
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Moving away from legacy code with BDD

Moving away from legacy code

with BDD

Page 2: Moving away from legacy code with BDD

BDD Evangelist

BDD Practice Manager @Inviqa

Creator of Behat, Mink, PhpSpec2, Prophecy

Contributor to Symfony2, Composer

@everzet

Page 3: Moving away from legacy code with BDD

This talk is about

• Solving purely technical “TCIAM” problem using behavioural business analysis and discovery process

• Building a delivery strategy on the idea of the change appreciation

• Real-life experience

Page 4: Moving away from legacy code with BDD

This talk is not about

• Greenfield projects

• Maintenance-mode projects

• Solutions for everyone

• How to write code

Page 5: Moving away from legacy code with BDD

Legacy projects

Page 6: Moving away from legacy code with BDD

How most developers see their next project

Page 7: Moving away from legacy code with BDD

My next project

Page 8: Moving away from legacy code with BDD

My next project

His actual next project

Page 9: Moving away from legacy code with BDD

Agile, TDD, BDD, General QA, etc…

// TODO: refactor this later

Page 10: Moving away from legacy code with BDD

Is it really that bad?

Page 11: Moving away from legacy code with BDD

If the project can afford at least one full-time specialist on a payroll that whines how horrible this project is, then surely it did something right.

Page 12: Moving away from legacy code with BDD

// TODO: refactor this later

Page 13: Moving away from legacy code with BDD

// TODO: refactor this later

Page 14: Moving away from legacy code with BDD

// TODO: refactor this later

Page 15: Moving away from legacy code with BDD

This world is full of brilliant projects that nobody wants to whine about. Sadly, it’s often simply because there’s no one left to pay for that.

Page 16: Moving away from legacy code with BDD

The truth is: You deliver value!

Just not as effectively as you could

Page 17: Moving away from legacy code with BDD

• Great value + Awful code = Great product today

• Great value + Great code = Great product tomorrow

• No value + Any kind of code= Awful product anytime

Page 18: Moving away from legacy code with BDD

• Great value + Awful code = Great product today

• Great value + Great code = Great product tomorrow

• No value + Any kind of code= Awful product anytime

Page 19: Moving away from legacy code with BDD

// TODO: refactor this later

Agile, TDD, BDD, General QA, etc…

Page 20: Moving away from legacy code with BDD

How?

Page 21: Moving away from legacy code with BDD

Three popular options

1. Rewrite an entire application using “the right way”

2. Do technical refactoring

3. Do business-oriented rewrite using “BDD pipeline”

Page 22: Moving away from legacy code with BDD

#1: Full Rewrite

Page 23: Moving away from legacy code with BDD

#1: Full Rewrite

• Scrum / Kanban

• TDD / BDD / DDD / Other XP goodness

• New everything

• Mirroring functionality

Page 24: Moving away from legacy code with BDD

#1: Income

Page 25: Moving away from legacy code with BDD

6 Months later…

Page 26: Moving away from legacy code with BDD

#1: Almost there…

Page 27: Moving away from legacy code with BDD

#1: Full Rewrite

Just spaghetti, please: 4 man years

Full London meal (TDD, BDD, Agile, QA): ??? man years

Page 28: Moving away from legacy code with BDD

#2: Technical Refactoring

Page 29: Moving away from legacy code with BDD

#2: Technical Refactoring

• Blackbox testing

• New routing

• New templating system

• Migration of model layer (MySQL -> Mongo)

• Whatever else that is easy to replace

Page 30: Moving away from legacy code with BDD

#2: Income

Page 31: Moving away from legacy code with BDD

6 Months later…

Page 32: Moving away from legacy code with BDD

#2: Ta-da!!!

Page 33: Moving away from legacy code with BDD

– Your client. (most likely)

“Exactly what did you do here?”

Page 34: Moving away from legacy code with BDD

#3: BDD PIPELINEAKA Business-Focused rewrite

Page 35: Moving away from legacy code with BDD

Why do legacy projects suck?

Page 36: Moving away from legacy code with BDD

Cost

Time

Because of the cost of change

Page 37: Moving away from legacy code with BDD

… Of change where?

Page 38: Moving away from legacy code with BDD

Why do applications change?

Page 39: Moving away from legacy code with BDD

Welcome to the wonderland

of Behaviour Driven Development

Page 40: Moving away from legacy code with BDD

Questionnaire

1. Where is this project going?

2. Which features are going to change?

3. How are they going to change?

4. How to support that change?

Page 41: Moving away from legacy code with BDD

“BDD Pipeline”

1. Where is this project going?

2. Which features are going to change?

3. How are they going to change?

4. How to support that change?

• Impact Mapping

• Business Prioritisation

• Example (3 Amigos) Workshop

• BDD layers

Page 42: Moving away from legacy code with BDD

1. Where is this project going?

Impact Mapping

Page 43: Moving away from legacy code with BDD

– 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 44: Moving away from legacy code with BDD

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 45: Moving away from legacy code with BDD
Page 46: Moving away from legacy code with BDD

MVP

Page 47: Moving away from legacy code with BDD

Product Backlog

Page 48: Moving away from legacy code with BDD
Page 49: Moving away from legacy code with BDD

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

Page 50: Moving away from legacy code with BDD

2. Which features are going to change?

Business Prioritisation

Page 51: Moving away from legacy code with BDD

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

Page 52: Moving away from legacy code with BDD

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

benefit

actor

Page 53: Moving away from legacy code with BDD

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

Page 54: Moving away from legacy code with BDD

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

Page 55: Moving away from legacy code with BDD

Three layers of a User-Story

• Business rule(s)

• Communication

• Acceptance criteria

Page 56: Moving away from legacy code with BDD

Three layers of a User-Story

• Business rule(s) == Acceptance criteria

• Communication

Page 57: Moving away from legacy code with BDD

Three layers of a User-Story

• Business rule(s) == Acceptance criteria

• Communication == Examples

Page 58: Moving away from legacy code with BDD

Three layers of a User-Story

• Business rule(s)

• Communication == Examples == Acceptance criteria

Page 59: Moving away from legacy code with BDD

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 60: Moving away from legacy code with BDD

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 61: Moving away from legacy code with BDD

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 62: Moving away from legacy code with BDD

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 63: Moving away from legacy code with BDD

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 64: Moving away from legacy code with BDD

Given a customer previously bought a black sweater from me And I currently have three black sweaters left in stock When he returns the sweater for a refund Then I 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 65: Moving away from legacy code with BDD

4. How to make it work?Delivery

Page 66: Moving away from legacy code with BDD

Given a customer previously bought a black sweater from me And I currently have three black sweaters left in stock When he returns the sweater for a refund Then I 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 67: Moving away from legacy code with BDD

Architectural approaches

1. The Inside job

2. The Bridge

Page 68: Moving away from legacy code with BDD

Architectural approach#1 The Inside job

Page 69: Moving away from legacy code with BDD

Step#1: Identify change area

Page 70: Moving away from legacy code with BDD

Step#1: Identify old logic

Page 71: Moving away from legacy code with BDD

Step#2: 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 72: Moving away from legacy code with BDD

Step#3: 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 upcoming change easier

4. Make scenarios/tests green

Page 73: Moving away from legacy code with BDD
Page 74: Moving away from legacy code with BDD

Step#4: Make a change

1. Automate new scenarios

2. Make scenarios green by applying BDD loops

Page 75: Moving away from legacy code with BDD

Stories

Examples

Describe

ImplementDesign

Page 76: Moving away from legacy code with BDD

Architectural approach#2 The bridge

Page 77: Moving away from legacy code with BDD

Legacy system

Infrastructure

[GET] /products

Page 78: Moving away from legacy code with BDD

Legacy system

Infrastructure

[GET] /products

[GET] /products/123

Page 79: Moving away from legacy code with BDD

Legacy system

Infrastructure

[GET] /products

[GET] /products/123

New system

Page 80: Moving away from legacy code with BDD

Legacy system

Infrastructure

[GET] /products

[GET] /products/123

New system

New system

Page 81: Moving away from legacy code with BDD

Step#0: Prepare for any change

1. Prepare the application infrastructure for bridging

a. Share sessions

b. Share data

2. Prepare the server infrastructure for bridging

Page 82: Moving away from legacy code with BDD

Step#1: Make a change

1. Automate new scenarios

2. Make scenarios green by applying BDD loops

Page 83: Moving away from legacy code with BDD

#3: Income

Page 84: Moving away from legacy code with BDD

6 months later…

Page 85: Moving away from legacy code with BDD

#3: Same ashtrays, better car

Page 86: Moving away from legacy code with BDD

Stop dreaming of a greater code

Find a way to deliver a greater value

Page 87: Moving away from legacy code with BDD

We do that for clientsAnd coach / train others how to do it

http:// .com

Page 88: Moving away from legacy code with BDD

Thank you!

@everzet