106
MUD TIRES: GETTING TRACTION IN LEGACY CODE Cory Foy Senior Consultant Net Objectives @cory_foy [email protected] http://blog.coryfoy.com http://www.flickr.com/photos/or4n6e/4827075541

Mud Tires: Getting Traction in Legacy Code

Embed Size (px)

Citation preview

Page 3: Mud Tires: Getting Traction in Legacy Code

WHAT IS LEGACY CODE?

Page 4: Mud Tires: Getting Traction in Legacy Code

WHAT IS LEGACY CODE?

• Code we’ve gotten from somewhere else

Page 5: Mud Tires: Getting Traction in Legacy Code

WHAT IS LEGACY CODE?

• Code we’ve gotten from somewhere else

• Code we have to change, but don’t understand

Page 6: Mud Tires: Getting Traction in Legacy Code

WHAT IS LEGACY CODE?

• Code we’ve gotten from somewhere else

• Code we have to change, but don’t understand

• Demoralizing Code (Big Ball of Mud)

Page 7: Mud Tires: Getting Traction in Legacy Code

WHAT IS LEGACY CODE?

• Code we’ve gotten from somewhere else

• Code we have to change, but don’t understand

• Demoralizing Code (Big Ball of Mud)

• Code without automated unit tests

Page 8: Mud Tires: Getting Traction in Legacy Code

WHAT IS LEGACY CODE?

• Code we’ve gotten from somewhere else

• Code we have to change, but don’t understand

• Demoralizing Code (Big Ball of Mud)

• Code without automated unit tests

• Any code older than about 2 hours

Page 10: Mud Tires: Getting Traction in Legacy Code

Adding Behavior

Page 11: Mud Tires: Getting Traction in Legacy Code

Preparing to Add

Behavior

Adding Behavior

Page 12: Mud Tires: Getting Traction in Legacy Code

Adding Behavior

Preparing to Add

Behavior

Adding Behavior

Page 13: Mud Tires: Getting Traction in Legacy Code

Adding Behavior

Preparing to Add

Behavior

Adding Behavior

Removing Duplication

Page 14: Mud Tires: Getting Traction in Legacy Code

Adding Behavior

Preparing to Add

Behavior

Adding Behavior

Removing Duplication

Cleaning Technical

Debt

Page 15: Mud Tires: Getting Traction in Legacy Code

Adding Behavior

Preparing to Add

Behavior

Adding Behavior

Removing Duplication

Cleaning Technical

Debt

Page 16: Mud Tires: Getting Traction in Legacy Code

Adding Behavior

Preparing to Add

Behavior

Adding Behavior

Removing Duplication

Cleaning Technical

Debt

Prefactoring

Page 17: Mud Tires: Getting Traction in Legacy Code

Adding Behavior

Preparing to Add

Behavior

Adding Behavior

Removing Duplication

Cleaning Technical

Debt

Prefactoring Refactoring

Page 18: Mud Tires: Getting Traction in Legacy Code

Adding Behavior

Preparing to Add

Behavior

Adding Behavior

Removing Duplication

Cleaning Technical

Debt

Prefactoring Refactoring

Remodeling

Page 19: Mud Tires: Getting Traction in Legacy Code

Adding Behavior

Preparing to Add

Behavior

Adding Behavior

Removing Duplication

Cleaning Technical

Debt

Prefactoring Refactoring

Remodeling

Coding

Page 20: Mud Tires: Getting Traction in Legacy Code
Page 22: Mud Tires: Getting Traction in Legacy Code

Tools

Approaches

Strategies

http://www.flickr.com/photos/marcwathieu/4074508950

Page 31: Mud Tires: Getting Traction in Legacy Code
Page 32: Mud Tires: Getting Traction in Legacy Code
Page 33: Mud Tires: Getting Traction in Legacy Code
Page 34: Mud Tires: Getting Traction in Legacy Code
Page 35: Mud Tires: Getting Traction in Legacy Code
Page 36: Mud Tires: Getting Traction in Legacy Code
Page 37: Mud Tires: Getting Traction in Legacy Code
Page 38: Mud Tires: Getting Traction in Legacy Code
Page 39: Mud Tires: Getting Traction in Legacy Code
Page 40: Mud Tires: Getting Traction in Legacy Code

Strategies

Acceptance Test-Driven Development

Test-Driven Development

Pair Programming

Characterization Tests

Naked CRC

Tell the StoryRefactoring

Sensing Variables

Page 41: Mud Tires: Getting Traction in Legacy Code

Strategies

Acceptance Test-Driven Development

Test-Driven Development

Pair Programming

Characterization Tests

Naked CRC

Tell the StoryRefactoring

Sensing Variables

Page 42: Mud Tires: Getting Traction in Legacy Code

Strategies

Acceptance Test-Driven DevelopmentTest-Driven Development

Pair ProgrammingCharacterization Tests

Naked CRCTell the Story

Refactoring

Sensing Variables

Making Changes

Increasing Confidence

Gaining Understanding

Page 43: Mud Tires: Getting Traction in Legacy Code

http://www.flickr.com/photos/ransomtech/5811447011

Tell the StoryNaked CRC

Page 44: Mud Tires: Getting Traction in Legacy Code

Tell the Story

Page 45: Mud Tires: Getting Traction in Legacy Code

Naked CRC

Page 46: Mud Tires: Getting Traction in Legacy Code

http://www.flickr.com/photos/west_point/5863829218

Increasing Confidence

Sensing VariablesCharacterization Tests

Pair Programming

Page 47: Mud Tires: Getting Traction in Legacy Code

http://www.artima.com/weblogs/viewpost.jsp?thread=170799

Sensing Variables

Page 48: Mud Tires: Getting Traction in Legacy Code

http://www.artima.com/weblogs/viewpost.jsp?thread=170799

Sensing Variables

Page 49: Mud Tires: Getting Traction in Legacy Code

http://www.artima.com/weblogs/viewpost.jsp?thread=170799

Sensing Variables

Page 50: Mud Tires: Getting Traction in Legacy Code

http://www.artima.com/weblogs/viewpost.jsp?thread=170799

Characterization Tests

Page 51: Mud Tires: Getting Traction in Legacy Code

http://www.artima.com/weblogs/viewpost.jsp?thread=170799

Characterization Tests

Page 52: Mud Tires: Getting Traction in Legacy Code

http://www.artima.com/weblogs/viewpost.jsp?thread=170799

Characterization Tests

Page 53: Mud Tires: Getting Traction in Legacy Code
Page 54: Mud Tires: Getting Traction in Legacy Code
Page 55: Mud Tires: Getting Traction in Legacy Code
Page 56: Mud Tires: Getting Traction in Legacy Code
Page 57: Mud Tires: Getting Traction in Legacy Code

http://www.flickr.com/photos/slavin_fpo/3728404776

You need to

Change

ATDDTDD

Refactoring

Page 58: Mud Tires: Getting Traction in Legacy Code

Adding Behavior

Preparing to Add

Behavior

Adding Behavior

Removing Duplication

Cleaning Technical

Debt

Prefactoring Refactoring

Remodeling

Coding

Page 59: Mud Tires: Getting Traction in Legacy Code

Adding Behavior

Preparing to Add

Behavior

Adding Behavior

Removing Duplication

Cleaning Technical

Debt

Prefactoring Refactoring

Remodeling

Coding

ATDD

Page 60: Mud Tires: Getting Traction in Legacy Code

Adding Behavior

Preparing to Add

Behavior

Adding Behavior

Removing Duplication

Cleaning Technical

Debt

Prefactoring Refactoring

Remodeling

Coding

ATDDTDD

Page 61: Mud Tires: Getting Traction in Legacy Code

Adding Behavior

Preparing to Add

Behavior

Adding Behavior

Removing Duplication

Cleaning Technical

Debt

Prefactoring Refactoring

Remodeling

Coding

ATDDTDD

Refactoring

Page 62: Mud Tires: Getting Traction in Legacy Code

Example: Acceptance TDD Basic Employee CompensationEach week, hourly employees are paid • A standard wage per hour for the first 40 hours worked• 1.5 times their wage for each hour after the first 40 hours• 2 times their wage for each hour worked on Sundays and holidays

Page 63: Mud Tires: Getting Traction in Legacy Code

Example: Acceptance TDD

Standard Hours

Hol/Sun Hours

Wage Pay()

40 0 20

45 0 20

48 8 20

Basic Employee CompensationEach week, hourly employees are paid • A standard wage per hour for the first 40 hours worked• 1.5 times their wage for each hour after the first 40 hours• 2 times their wage for each hour worked on Sundays and holidays

Payroll.Fixtures.WeeklyCompensation

Page 64: Mud Tires: Getting Traction in Legacy Code

Example: Acceptance TDD

Standard Hours

Hol/Sun Hours

Wage Pay()

40 0 20 $800

45 0 20 $950

48 8 20 $1520

Basic Employee CompensationEach week, hourly employees are paid • A standard wage per hour for the first 40 hours worked• 1.5 times their wage for each hour after the first 40 hours• 2 times their wage for each hour worked on Sundays and holidays

Payroll.Fixtures.WeeklyCompensation

Page 65: Mud Tires: Getting Traction in Legacy Code

http://www.fitnesse.org

Page 66: Mud Tires: Getting Traction in Legacy Code

http://www.fitnesse.org

Page 67: Mud Tires: Getting Traction in Legacy Code

http://www.fitnesse.org

Page 68: Mud Tires: Getting Traction in Legacy Code

http://www.fitnesse.org

Page 69: Mud Tires: Getting Traction in Legacy Code

A test is not a unit test if:

- It talks to the database- It communicates across the network- It touches the file system- It can't run at the same time as any of your other unit tests- You have to do special things to your environment (such as editing config files) to run it.

Page 72: Mud Tires: Getting Traction in Legacy Code

http://vinkamat.com/2011/tdd-unit-testing-and-benefits/

Red

Green

Page 73: Mud Tires: Getting Traction in Legacy Code

http://vinkamat.com/2011/tdd-unit-testing-and-benefits/

Red

Green

Refactor

Page 74: Mud Tires: Getting Traction in Legacy Code
Page 75: Mud Tires: Getting Traction in Legacy Code
Page 76: Mud Tires: Getting Traction in Legacy Code
Page 77: Mud Tires: Getting Traction in Legacy Code
Page 78: Mud Tires: Getting Traction in Legacy Code
Page 79: Mud Tires: Getting Traction in Legacy Code
Page 80: Mud Tires: Getting Traction in Legacy Code
Page 81: Mud Tires: Getting Traction in Legacy Code
Page 82: Mud Tires: Getting Traction in Legacy Code

(Refactoring is a) disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior

Page 83: Mud Tires: Getting Traction in Legacy Code
Page 84: Mud Tires: Getting Traction in Legacy Code
Page 85: Mud Tires: Getting Traction in Legacy Code
Page 86: Mud Tires: Getting Traction in Legacy Code
Page 87: Mud Tires: Getting Traction in Legacy Code
Page 88: Mud Tires: Getting Traction in Legacy Code

http://www.flickr.com/photos/phluke/62175794

Feather’s ApproachATDD Approach

Edit and Pray

Page 89: Mud Tires: Getting Traction in Legacy Code

Feather’s Approach

Page 90: Mud Tires: Getting Traction in Legacy Code

Identify Change Points

Feather’s Approach

Page 91: Mud Tires: Getting Traction in Legacy Code

Identify Change Points

Find Test Points

Feather’s Approach

Page 92: Mud Tires: Getting Traction in Legacy Code

Identify Change Points

Find Test Points

Break Dependencie

s

Feather’s Approach

Page 93: Mud Tires: Getting Traction in Legacy Code

Identify Change Points

Find Test Points

Break Dependencie

s

Write Tests

Feather’s Approach

Page 94: Mud Tires: Getting Traction in Legacy Code

Identify Change Points

Find Test Points

Break Dependencie

s

Write Tests

Make Changes

Feather’s Approach

Page 95: Mud Tires: Getting Traction in Legacy Code

Identify Change Points

Find Test Points

Break Dependencie

s

Write Tests

Make Changes

Refactor

Feather’s Approach

Page 96: Mud Tires: Getting Traction in Legacy Code

ATDD Approach

Page 97: Mud Tires: Getting Traction in Legacy Code

WriteAcceptance

Tests

ATDD Approach

Page 98: Mud Tires: Getting Traction in Legacy Code

WriteAcceptance

Tests WriteCharacterization

Tests

ATDD Approach

Page 99: Mud Tires: Getting Traction in Legacy Code

WriteAcceptance

Tests WriteCharacterization

Tests

ImplementBehavior

ATDD Approach

Page 100: Mud Tires: Getting Traction in Legacy Code

WriteAcceptance

Tests WriteCharacterization

Tests

ImplementBehavior

Get All Tests to Pass

ATDD Approach

Page 101: Mud Tires: Getting Traction in Legacy Code

WriteAcceptance

Tests WriteCharacterization

Tests

ImplementBehavior

Get All Tests to Pass

Celebrate!

ATDD Approach

Page 102: Mud Tires: Getting Traction in Legacy Code

WriteAcceptance

Tests WriteCharacterization

Tests

ImplementBehavior

Get All Tests to Pass

Celebrate!

ATDD Approach

Page 103: Mud Tires: Getting Traction in Legacy Code

WriteAcceptance

Tests WriteCharacterization

Tests

ImplementBehavior

Get All Tests to Pass

Celebrate!

ATDD Approach

Page 104: Mud Tires: Getting Traction in Legacy Code

WriteAcceptance

Tests WriteCharacterization

Tests

ImplementBehavior

Get All Tests to Pass

Celebrate!

ATDD Approach

Page 105: Mud Tires: Getting Traction in Legacy Code