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

Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

Embed Size (px)

Citation preview

Page 1: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

Big rewrites without big risksFlavius Ștef

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

Page 2: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

About meI train and coachpeople in agile, lean

and leadership

Page 3: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

Iterative and incremental

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

Page 4: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

Why?

time

risk

time

risk

validate

validate validate validate validate

Page 5: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

New skill: story splitting

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

Page 6: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

xx x

x

x

x x

x x x

Splittingfeaturesis easy

Page 7: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

THE PROBLEM OFTHE PROBLEM OFINCREMENTAL REFACTORINGINCREMENTAL REFACTORING

Page 8: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

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: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

IncrementalIncrementalArchitectureArchitectureRefactoring?Refactoring?

Page 10: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

Agile doesn't apply here!!!

Page 11: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

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: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

STRATEGIESSTRATEGIES

Page 13: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

Sorry, stillno silver bullet

Get creative!Get creative!

Page 14: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

1. Fake it till you make it

Page 15: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

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: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

GUI(C#)

Middleware(C#)

RPC HardwareManager

(C++)Packet

Generators

RPC

Old Product

WIN CLIENT TRAFFIC GENERATOR

Page 17: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

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: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

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

Middleware(C#)

LINUX CLIENT

Mono

WebUI

Page 19: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

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

Middleware(C#)

LINUX CLIENT

Mono

WebUI Send basic message between the two.

Page 20: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

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: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

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: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

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: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

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: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

Timeline

Research

Make it run on Linux

WalkingSkeleton

Stories for demo version10d

20d

7d

15d

About 1 month

Page 25: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

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

Page 26: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

Same product, different team

Middleware(C#)

Mono

WebUI

RPCHardwareManager

(C++)Packet

Generators

RPC

TRAFFIC GENERATORLINUX CLIENT

Page 27: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

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

HardwareManager

(C++)

MFC WinAPI

STL Boost

Find substitutes

Page 28: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

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: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

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: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

Step 3. Unit testing (2 Weeks)

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

StringTestvalidateagainst

validateagainst

Page 31: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

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: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

Step 5. Incrementally remove Win dependency

2m 2m 1m

Remove MFC Remove WinAPI Finaltesting

Windows Linux

Page 33: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

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: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

3. One bite at a time

https://flic.kr/p/CaNo1

Page 35: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

Rewrite #1

4m 7m

Rewrite #2 BetaLaunch

An interface rewrite

2m

Abort!

Page 36: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

Rally:circa 2008

Page 37: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

Rally:circa 2009

Page 38: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

What about the stories

page?

Page 39: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

Oh, there were

changes...

Page 40: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

4. Rewrite the story book

Page 41: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

Three Amigos

Dev QA BA

Feature: ________

Scenario:________

Given ________When ________Then _________

Scenarios

Page 42: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

PROCESSPROCESS

Page 43: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

Set goalAnalyze

architectureCreatebacklog

Talk to QA

Pickrefactoring

RefactorTest

Update backlog

Stop

Done?

YES

Integrate

NO

Add testsif needed

Page 44: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

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: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

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: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

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: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

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: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

Stop

YES

Talk to QACreatebacklog

Analyzearchitecture

Set goal

PickrefactoringRefactorTest

Update backlog

Done?

Integrate

NO

Add testsif needed

Mikado Method

Page 49: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

Goal

Prerequisite Prerequisite

Prerequisite Prerequisite Prerequisite

The Mikado Method

Page 50: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

Mikado Method

Move servicefrom Windows

to Linux

Fix Win APIcompiler errs

Fix MFCcompiler errs

Fix CStringcompiler errs

WriteCMyString

Replace CStringinvocations

Page 51: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

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: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

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: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

CONCLUSIONCONCLUSION

Page 54: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

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: Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference

THANKS!

Flavius Ștef

Twitter: @flaviusstefSlides: slideshare.net/fstef

www.mozaicworks.com/blog/