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?
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
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