taming the monster legacy code beast

47
PROACT ION M E N T O R S Taming Legacy Code Monsters

Upload: caleb-jenkins

Post on 10-May-2015

1.822 views

Category:

Technology


1 download

DESCRIPTION

Does that legacy code beast stifle your creativity? Do you stay up late at night frightened that someone might touch *that* piece of code? Learn some practical steps on how you can slay the legacy code beasts, divide and conquer, and deliver value to your customers.

TRANSCRIPT

Page 1: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

Taming Legacy Code Monsters

Page 2: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

Caleb *

* I’m here to help.

Page 3: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

Page 4: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

10 Reasons your software Sucks(and the 10 practices to fix it)

Last year

Page 5: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

DevelopmentObject Orientation

SOLID

Patterns

Secure Coding

Team WorkAutomated Tests

Source Control

Automated Builds

ProcessAgile, Lean, XP

Team Dynamics

Continuous Learning

Bui ld ing teams that engineer better software

Development ∙ Team Work ∙ Process

Page 6: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

back to…

Taming Legacy Code Monsters

Page 7: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

back to…

Taming Legacy Code Monsters

Page 8: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

Definition “Legacy”n. Software that I’m afraid to maintain,

extend, or change it actually scares me to

touch that code.

Page 9: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

What’s the difference between an application and

UI Auth Validation

Rules Workflow Processor

Services Data Cache

Page 10: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

Legacy Monster

UI Auth Validation

Rules Workflow Processor

Services Data Cache

Page 11: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

Legacy MonsterStatic ConfigStatic ProxyProcessor SettingsData ConnectionsRules Configurations

Rules

Processor

Data

Coupling

Cou

plin

g

Coupling

Coupling

CouplingCoupling

Page 12: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

Legacy MonsterSolution contained over 68 projects.

Most of which were not used.

No horizontal layers.

Required IIS 6 / legacy URL rewriter / 32 bit C Lib / IIS Rules export/import /

Database Connections / Proper Configuration X 3

To run or test ANY part on a dev box…

Page 13: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

Know your FoeStra

tegy #1

Page 14: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

nDepend

Strategy #1

Page 15: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

Visual Studio Dependency Graph

Strategy #1

Page 16: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

Strategy #1

DemoUsing theVisual Studio Dependency Graph

Page 17: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

Pro tip:Look for big blobs & thick lines to concrete types

Strategy #1

Demo

Page 18: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

Strategy #2

Create a

Safety Net

Page 19: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

Strategy #2

Source Control+ Test

Page 20: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

Strategy #2

Source Control+ Test

Page 21: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

Strategy #2

Source Control

Page 22: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

// source// trunk

// r1 // r2 // r3

// r1.1

// trunk

//

// svn / git / tfs ..

Branching for FUN!

Page 23: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

Strategy #2

Tests

Unit TestsIntegrationRegressionLoad TestsEtc…

Page 24: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

Isolation and White box Unit Testing for .NET

Legacy MonsterStatic ConfigStatic IProxyProcessor SettingsData ConnectionsRules Configurations

Rules

Processor

Data

“Pex automatically generates test suites with high code coverage. …[and] finds interesting input-output values of your methods, which you can save as a small test suite with high code coverage. Microsoft Pex is a Visual Studio add-in for testing .NET Framework applications.”

http://research.microsoft.com/en-us/projects/pex/

Demo: Safety Net

Page 25: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

what about hard to test code?refactoring testability

Page 26: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

private IList<Bean> goodBeans { get; set;}private IList<Bean> badBeans { get; set;}

public void AddBean(Bean bean){

if (bean.size > 10)goodBeans.Add(bean);

elsebadBeans.Add(bean);

}public void UpdateBeans(){ BeanData.Update(goodBeans); goodBeans.Clear(); badBeans.Clear();}

Page 27: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

Clearly an arbitrary example1Does represent actual production code that I have worked with

Usage scenario is2AddBean(b); AddBean(b), UpdateBeans();

How can we test the AddBean() Logic?3

Page 28: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

private IList<Bean> goodBeans { get; set;}private IList<Bean> badBeans { get; set;}

public void AddBean(Bean bean){

if (bean.size > 10)goodBeans.Add(bean);

elsebadBeans.Add(bean);

}public void UpdateBeans(){ BeanData.Update(goodBeans); goodBeans.Clear(); badBeans.Clear();}

public IList<Bean> GoodBeans { get; private set;}private Ilist <Bean>badBeans { get; set;}

public void AddBean(Bean bean){

if (bean.size > 10)GoodBeans.Add(bean);

elsebadBeans.Add(bean);

}public void UpdateBeans(){ BeanData.Update(goodBeans); GoodBeans.Clear(); badBeans.Clear();}

A: create a readonlyaccessor to “sense” thegoodBean state externally

Page 29: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

public void UpdateBeans(){ BeanData.Update(goodBeans);

goodBeans.Clear(); badBeans.Clear();

}

What about the UpdateBeans() method?public void UpdateBeans(){ BeanData.Update(goodBeans);

goodBeans.Clear(); badBeans.Clear();

if (OnBeansUpdate != null) OnBeansUpdate();}

public event Action OnBeansUpdate;

Page 30: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

Not a silver bullet

still need to make sure that we are testing “the right” things, and not just hitting some magical number

still need to make sure we have healthy tests

Code Coverage + Continuous Integration

Pro tip

Page 31: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

Code Coverage + Continuous IntegrationCreates a base line or smoke test to look for

Watch trends over magic percent numbers

Pro tip

Page 32: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

Code Coverage + Continuous IntegrationTeam City Code Coverage

Page 33: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

Code Coverage + Continuous IntegrationSonar

Page 34: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

Strategy #3

Page 35: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

Strategy #3

Divide and Conquer

(pick your battles)

Page 36: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S36

Commitment

Page 37: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S37

Commitment Raise your hand and repeat after me,

Page 38: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S38

Commitment Raise your hand and repeat after me,

I will not practice bad code.

Page 39: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

Page 40: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

“Resist Legacy Coupling”

Page 41: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

“Resist Legacy Coupling”Legacy Monster

Static ConfigStatic ProxyProcessor SettingsData ConnectionsRules Configurations

Rules

Processor

Data

Coupling

Cou

plin

g

CouplingC

oupling CouplingCoupling

tight coupling = change anywhereaffects everything

New Functionality

Needs IProxy

don’t reference Config Monster

use DI for only what you need (IProxy)

static Config class leads to Heavy Weight testing

Page 42: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

Introduce SOLID principals on new development… gradually improve code over time

http://developingux.com/di/

Page 43: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

wrap up

Page 44: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

wrap upKnow your Foe

Use a Safety Net

Divide and Conquer

Page 45: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

@calebjenkins

@proactionmentor

http://developingux.com

[email protected]

Thank you!

PROACTION

M E N T O R S

Page 46: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

Photo Credits

http://www.flickr.com/photos/boogeyman13/2432667459/

http://www.flickr.com/photos/stopthegears/50553611/

http://www.flickr.com/photos/pochateca/324414459

http://www.flickr.com/photos/27620885@N02/2594362917

© Michael Cummings - http://dreaminpictures.com

Page 47: Taming the Monster Legacy Code Beast

PROACTION

M E N T O R S

http://www.flickr.com/photos/flyingturtle/3976070342/

http://www.lostechies.com/blogs/derickbailey/archive/2009/02/11/solid-development-principles-in-motivational-pictures.aspx

http://www.flickr.com/photos/jfravel/1001472806/

http://www.flickr.com/photos/flyingturtle/3976076272/

http://www.flickr.com/photos/27620885@N02/2594363003