Legacy Code: Evolve or Rewrite?

Post on 01-Dec-2014

94 Views

Category:

Software

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

You have to deliver ambitious new features but your codebase is a huge mess of legacy technologies, with no test? It is very tempting to throw it all away and rewrite everything from scratch, but is it wise when you consider the associated cost, risk and delayed time-to-market? Through an experience report, we'll show a "Strangler Application" strategy where only carefully selected areas of legacy code are rewritten. Agile development techniques like BDD or TDD remain necessary, with some adjustments. We'll also describe step by step the overall thinking process you can use to deal with large legacy code bases efficiently. First presented at Agile France 2013, and in countless Brown Bag Lunches since, a best-seller! Video (In French) here: http://www.infoq.com/fr/presentations/code-legacy

Transcript

Legacy CodeEvolve or Rewrite ?

A retrospective

Cyrille Martraire - @cyriux -

http://1.bp.blogspot.com/_SOzNIrpkT7M/TIhYjDKKz-I/AAAAAAAABjo/NCPSaVmZn0w/s1600/100_2824.jpg

Passionate developer

PARIS Since 1999

!@cyriux

Paris Software Craftsmanship Community

http://www.meetup.com/paris-software-craftsmanship/

TDDBDDDDDLegacy

LEGACY

Legacy:Evolve or rewrite?

Actual Example

Once upon a time…

There was a frustrated ambition

We Want:

Large Ambition

Asset Management

wanna do big things stuck with a legacy

So what do we do?

REWRITE

STOP!

We all want to rewrite

hard to release regressions

Legacy

Legacy

No Test& Technical Debt too

http://skillsmatter.com/podcast/design-architecture/talk-from-eric-evans

Plenty of Legacy code working since 1993

Redoing = Waste + Risk

Poorly designed codeWorking wellNever changed

Is OK

KEEP iT

KEEP GUI

, DB,

APP Ser

ver,

middleware

We Want NEW FEATURES!CHA

NGE

SOMETH

ING

Haz Change?

JUSTDO IT!

QUICK

Did we break something?

http://martinezglass.com

No Test

Takes a lot of time

No Test+ Debug!

Just Do It: Not that quick

Again and again

Could we do better?

EVOLVE

Surround with tests FIRST

Surround with tests!

Testing legacy code is hard & slow

Testing is an investment

Driver = Cost of testing

A matter of velocity

Legacy testing effort Vs.

All new tested code?

Is it worth it?

1:4(Ok, I totally made it up)

ratio

REDO

Differentiating to the business?

The CEO will tell you

Not differentiating?

BUY

&ADA

PT

your

proc

ess

Differentiating!

REWRITE

• Why not, but not now • Don't get lost redoing everything forever

"What if we also rewrote this crappy part?"

...

JUSTENOUGH

You cannotrewrite all

You can rewrite

Where to stop?

What to rewrite?

Find boundaries

What to rewrite?

Discover the app

!!

Read the documents

Interview people

Use the application

Read the code

Fix bugs

Visualize[primary flow & support features]

http://www.fimarkets.com/pagesen/back-middle-front-office.php

Visualize[primary flow & support features]

http://www.fimarkets.com/pagesen/back-middle-front-office.php

Visualize[primary flow & support features]

http://www.fimarkets.com/pagesen/back-middle-front-office.php

http://staff.bath.ac.uk/enssa/LPDev.htm

Asset Inventory

Asset Capture

http://martinfowler.com/bliki/AssetCapture.html

Engine

Exhaust

Transmission

Asset Capture

Focus on one single asset : the engine

http://martinfowler.com/bliki/AssetCapture.html

Engine

Exhaust

Transmission

Main concepts[in selling-something business]

Trading

Financial Instruments

Main concepts[in selling-something business]

Trading

Financial Instruments

DON’t

TOUCH

REWRITE

DOMAIN FTW!

BOUNDARIES& STRUCTURE

Agree on maxims [communicate the plan]

• “Only one work site at a time: instruments” !

• “When in Rome, do as Romans do”

"The code says it all"

Legacy: Fossilized Domain Expertise

http://newspaper.li/fossil/

•inspiration

•obfuscated

Rewrite:!

because of CHANGES (or it’s a bad idea)

needs

Rewrite:!

must inject NEW knowledge

Rewrite:!

need business ANALYSIS

WHOLETEAM

Like a new project from

scratch!

So how do we

integrate?

STRANGLE

Strangler application

A new module will progressively strangle the

former one, for one single asset

only

http://www.flickr.com/photos/louisfoecy/4114597043http://martinfowler.com/bliki/StranglerApplication.html

Feature Toggles

!

Progressively turn off legacy functionalities & turn on the new ones

NEWOLD

if(c == category1) {legacy.compute(...)} else if(c == category2) {strangler.compute(...)} //...

Grow a Bubble Context

!

Listen to domain experts High hygiene standards

Pair-programming TDD, BDD, DDD

Invest in domain knowledge

• Bi-weekly 30mn training sessions

Dream model must pass every scenario

Bespoke custom DREAM MODEL

Given a floating rate bond on EURIBOR 3M And a nominal of 15M EUR And an issue date of 2011/06/15 And an end date of 2012/06/14 And an SEMI_ANNUAL calculation period !When the EURIBOR 3M evolves:

| 2011/09/15 | 3.5% | | 2012/03/15 | 4.0% | !

Then the cash-flows are: | 2011/12/13 | 23000 | | 2012/06/14 | 25500 |

Anti-corruption layer

Adapter

API

SPI

Easier to integrate by construction

bespoke lib

Old code: Freeze it

Rewrite=

clear boundaries +

new strangler application +

minimal integration

Deliver Value

Quickly

Questions? Did you try similar things too?

Let’s discuss!

@cyriux

Follow me @cyriux !

Slides: slideshare.net/cyriux Blog: cyrille.martraire.com

!

In Paris? Join !

Merci

top related