big rewrites without big risks

55
Big rewrites without big risks Flavius Ștef hps://flic.kr/p/9iuMzn

Upload: flavius-stef

Post on 10-Aug-2015

159 views

Category:

Engineering


4 download

TRANSCRIPT

Page 1: Big rewrites without big risks

Big rewrites without big risksFlavius Ștef

https://flic.kr/p/9iuMzn

Page 2: Big rewrites without big risks

About meI train and coachpeople in agile, lean

and leadership

Page 3: Big rewrites without big risks

Iterative and incremental

Images: http://www.yoomee.com/about-agile

Page 4: Big rewrites without big risks

Why?

time

risk

time

risk

validate

validate validate validate validate

Page 5: Big rewrites without big risks

New skill: story splitting

● Create-Read-Update-Delete● Workflow steps● Less usability first● etc.

Page 6: Big rewrites without big risks

xx x

x

x

x x

x x x

Splittingfeaturesis easy

Page 7: Big rewrites without big risks

THE PROBLEM OFTHE PROBLEM OFINCREMENTAL REFACTORINGINCREMENTAL REFACTORING

Page 8: Big rewrites without big risks

Sometimes we need a new architecture

● Go faster● Reduce number of bugs● Improve an NFR● Respond to client demands● Respond to market (ex: cloud, mobile, web)

Page 9: Big rewrites without big risks

IncrementalIncrementalArchitectureArchitectureRefactoring?Refactoring?

Page 10: Big rewrites without big risks

Agile doesn't apply here!!!

Page 11: Big rewrites without big risks

But the questions remain

How do we knowthe app still works?

How do we know how much is done?

How do we knowwhen we'll finish?

Page 12: Big rewrites without big risks

STRATEGIESSTRATEGIES

Page 13: Big rewrites without big risks

Sorry, stillno silver bullet

Get creative!Get creative!

Page 14: Big rewrites without big risks

1. Fake it till you make it

Page 15: Big rewrites without big risks

Product 1Desktop (C#)Windows

Product 2 ~ Product 1Desktop (C#)Windows

Product 3Desktop (C#)Windows

Front-end platformJava, JS

AwesomeNextGen Product

Linux-basedWeb UI (Java, JS)

Page 16: Big rewrites without big risks

GUI(C#)

Middleware(C#)

RPC HardwareManager

(C++)Packet

Generators

RPC

Old Product

WIN CLIENT TRAFFIC GENERATOR

Page 17: Big rewrites without big risks

GUI(C#)

Middleware(C#)

RPC HardwareManager

(C++)Packet

Generators

RPC

Step 1. Research (1 Sprint)

TRAFFIC GENERATOR

GUI(C#)

Middleware(C#)

RPC HardwareManager

(C++)Packet

Generators

RPC

TRAFFIC GENERATOR

GUI(C#)

Middleware(C#)

RPC HardwareManager

(C++)Packet

Generators

RPC

TRAFFIC GENERATOR

WIN CLIENT

WIN CLIENT

WIN CLIENT

Page 18: Big rewrites without big risks

Step 2. Make MW run on Linux (2 Sprints)

Middleware(C#)

LINUX CLIENT

Mono

WebUI

Page 19: Big rewrites without big risks

Step 3. Link web UI with middleware (1 week)

Middleware(C#)

LINUX CLIENT

Mono

WebUI Send basic message between the two.

Page 20: Big rewrites without big risks

Step 3. Link web UI with middleware (1 week)

Middleware(C#)

LINUX CLIENT

Mono

WebUI

C# bindingsexist

PROBLEM:Java bindingsdon't exist

RPCexpected

Page 21: Big rewrites without big risks

Step 4. Walking skeleton (2 days)

Middleware(C#)

LINUX CLIENT

Mono

WebUI

Old MW(C#)

Configuredifferentscenarios Dump to disk

Hack: load dump

HardwareManager

(C++)Packet

Generators

RPC

TRAFFIC GENERATOR

x

Start

Conf. #: 3

Google Chrome

OK!

Page 22: Big rewrites without big risks

Step 4. Walking skeleton (2 days)

Middleware(C#)

LINUX CLIENT

Mono

WebUI

RPC

Old MW(C#)

Configuredifferentscenarios Dump to disk

Hack: load dump

HardwareManager

(C++)Packet

Generators

RPC

TRAFFIC GENERATORx

Start

Conf. #: 3

Google Chrome

Page 23: Big rewrites without big risks

Step 5. Read+write configuration (3 weeks)

Middleware(C#)

LINUX CLIENT

Mono

WebUI

RPCHardwareManager

(C++)Packet

Generators

RPC

TRAFFIC GENERATOR

RPC endpoint in C# existed in old product.New product built Java RPC incrementally.

Read: How many NICs in the configuration?Read: What are their Ips?Write: Set IP of NIC #4Write: Add a machine to configurationRead: Another statistic...

BACKLOG

Page 24: Big rewrites without big risks

Timeline

Research

Make it run on Linux

WalkingSkeleton

Stories for demo version10d

20d

7d

15d

About 1 month

Page 25: Big rewrites without big risks

2. I just don't love you anymorehttps://flic.kr/p/rrHjG

Page 26: Big rewrites without big risks

Same product, different team

Middleware(C#)

Mono

WebUI

RPCHardwareManager

(C++)Packet

Generators

RPC

TRAFFIC GENERATORLINUX CLIENT

Page 27: Big rewrites without big risks

Step 1. Analyze dependencies & possible replacements (2 Weeks)

HardwareManager

(C++)

MFC WinAPI

STL Boost

Find substitutes

Page 28: Big rewrites without big risks

Step 2. Proof of concept (2 Months)

HardwareManager

(C++)

MFC WinAPI

Hack alternatives for:- (De)Serialization (MFC)- IPC (WinAPI)- …

STL Boost

CString → CMyStringCArray → CMyArray

Page 29: Big rewrites without big risks

Step 2. Proof of concept (2 Months)

“Hacked”HardwareManager

STL Boost

PacketGenerators

#ifdef __vm

Implemented ~1% of use cases- Select only one HW card- Comment out other code

Page 30: Big rewrites without big risks

Step 3. Unit testing (2 Weeks)

CString sut = “foo”; CMyString sut = “foo”;

StringTestvalidateagainst

validateagainst

Page 31: Big rewrites without big risks

Step 4. Performance testing (2 Weeks)

CFile sut; CMyFile sut;

StringPerformanceTest

validateagainst

validateagainst

for (i=0; i<20000; i++)

CFile (MFC) 20x faster than CMyFile (Boost)

Page 32: Big rewrites without big risks

Step 5. Incrementally remove Win dependency

2m 2m 1m

Remove MFC Remove WinAPI Finaltesting

Windows Linux

Page 33: Big rewrites without big risks

Process

TRUNK

DEV

...1w

Run

tes

tsR

un t

ests

3d

CodeFreezePractices:

● Software buildable and running at all times● Pull weekly from trunk● Run regression (10.000+ tests) every 3 days● Continuous integration (team level)

Page 34: Big rewrites without big risks

3. One bite at a time

https://flic.kr/p/CaNo1

Page 35: Big rewrites without big risks

Rewrite #1

4m 7m

Rewrite #2 BetaLaunch

An interface rewrite

2m

Abort!

Page 36: Big rewrites without big risks

Rally:circa 2008

Page 37: Big rewrites without big risks

Rally:circa 2009

Page 38: Big rewrites without big risks

What about the stories

page?

Page 39: Big rewrites without big risks

Oh, there were

changes...

Page 40: Big rewrites without big risks

4. Rewrite the story book

Page 41: Big rewrites without big risks

Three Amigos

Dev QA BA

Feature: ________

Scenario:________

Given ________When ________Then _________

Scenarios

Page 42: Big rewrites without big risks

PROCESSPROCESS

Page 43: Big rewrites without big risks

Set goalAnalyze

architectureCreatebacklog

Talk to QA

Pickrefactoring

RefactorTest

Update backlog

Stop

Done?

YES

Integrate

NO

Add testsif needed

Page 44: Big rewrites without big risks

Analyzearchitecture

Createbacklog

Talk to QA

PickrefactoringRefactorTest

Update backlog

Stop

Done?

YES

Integrate

NO

Add testsif needed

Business“Switch database vendors”“Implement new features faster”

Or Technical“Support 3000 concurrent connections”“Centralize security controls”

Set goal

Page 45: Big rewrites without big risks

Set goalCreatebacklog

Talk to QA

PickrefactoringRefactorTest

Update backlog

Stop

Done?

YES

Integrate

NO

Add testsif needed

SWOT Analysis(Strengths, Weaknesses, Opportunities, Threats)- What do we keep?- What do we drop?- What do we improve?

Analyzearchitecture

Page 46: Big rewrites without big risks

Analyzearchitecture

Set goal Talk to QA

PickrefactoringRefactorTest

Update backlog

Stop

Done?

YES

Integrate

NO

Add testsif needed

Architecture Epics“Remove MFC”

“Move DB code from JSPs”

Createbacklog

Page 47: Big rewrites without big risks

Createbacklog

Analyzearchitecture

Set goal

PickrefactoringRefactorTest

Update backlog

Stop

Done?

YES

Integrate

NO

Add testsif needed

What is the testing strategy?Automation vs. exploratory

How oftenMake sure testers are available

Talk to QA

Page 48: Big rewrites without big risks

Stop

YES

Talk to QACreatebacklog

Analyzearchitecture

Set goal

PickrefactoringRefactorTest

Update backlog

Done?

Integrate

NO

Add testsif needed

Mikado Method

Page 49: Big rewrites without big risks

Goal

Prerequisite Prerequisite

Prerequisite Prerequisite Prerequisite

The Mikado Method

Page 50: Big rewrites without big risks

Mikado Method

Move servicefrom Windows

to Linux

Fix Win APIcompiler errs

Fix MFCcompiler errs

Fix CStringcompiler errs

WriteCMyString

Replace CStringinvocations

Page 51: Big rewrites without big risks

If you need some guidance selecting the refactoring

http://www.sigs.de/download/oop_08/Stal%20Mi3-4.pdf+ Michael Stal: Architecture Refactoring Catalog

Page 52: Big rewrites without big risks

Michael Stal: source of architecture refactorings● Rename Entities● Remove Duplicates● Introduce Abstraction

Hierarchies● Remove Unnecessary

Abstractions● Substitute Mediation with

Adaptation● Break Dependency Cycles● Inject Dependencies● Insert Transparency Layer● Reduce Dependencies with

Facades● Merge Subsystems

● Split Subsystems● Enforce Strict Layering● Move Entities● Add Strategies● Enforce Symmetry● Extract Interface● Enforce Contract● Provide Extension

Interfaces● Substitute Inheritance with

Delegation● Provide Interoperability

Layers● Aspectify

● Integrate DSLs● Add Uniform Supp. to

Runtime Aspects● Add Configuration Subsystem● Introduce the Open/Close

Principle● Optimize with Caching● Replace Singleton● Separate Synchronous and

Asynchronous Processing● Replace Remote Methods

with Messages● Add Object Manager● Change Unidirectional

Association to Bidirectional

Page 53: Big rewrites without big risks

CONCLUSIONCONCLUSION

Page 54: Big rewrites without big risks

It's hard, but it can be done

Chunk the problem down

Encapsulate, stub, simulate

Work incrementally

Run tests

Validate against the goal

SUMMARY

Page 55: Big rewrites without big risks

THANKS!

Flavius Ștef

Twitter: @flaviusstefSlides: slideshare.net/fstef

www.mozaicworks.com/blog/