Mud Tires: Getting Traction in Legacy Code

Preview:

Citation preview

WHAT IS LEGACY CODE?

WHAT IS LEGACY CODE?

• Code we’ve gotten from somewhere else

WHAT IS LEGACY CODE?

• Code we’ve gotten from somewhere else

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

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)

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

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

Adding Behavior

Preparing to Add

Behavior

Adding Behavior

Adding Behavior

Preparing to Add

Behavior

Adding Behavior

Adding Behavior

Preparing to Add

Behavior

Adding Behavior

Removing Duplication

Adding Behavior

Preparing to Add

Behavior

Adding Behavior

Removing Duplication

Cleaning Technical

Debt

Adding Behavior

Preparing to Add

Behavior

Adding Behavior

Removing Duplication

Cleaning Technical

Debt

Adding Behavior

Preparing to Add

Behavior

Adding Behavior

Removing Duplication

Cleaning Technical

Debt

Prefactoring

Adding Behavior

Preparing to Add

Behavior

Adding Behavior

Removing Duplication

Cleaning Technical

Debt

Prefactoring Refactoring

Adding Behavior

Preparing to Add

Behavior

Adding Behavior

Removing Duplication

Cleaning Technical

Debt

Prefactoring Refactoring

Remodeling

Adding Behavior

Preparing to Add

Behavior

Adding Behavior

Removing Duplication

Cleaning Technical

Debt

Prefactoring Refactoring

Remodeling

Coding

Tools

Approaches

Strategies

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

Strategies

Acceptance Test-Driven Development

Test-Driven Development

Pair Programming

Characterization Tests

Naked CRC

Tell the StoryRefactoring

Sensing Variables

Strategies

Acceptance Test-Driven Development

Test-Driven Development

Pair Programming

Characterization Tests

Naked CRC

Tell the StoryRefactoring

Sensing Variables

Strategies

Acceptance Test-Driven DevelopmentTest-Driven Development

Pair ProgrammingCharacterization Tests

Naked CRCTell the Story

Refactoring

Sensing Variables

Making Changes

Increasing Confidence

Gaining Understanding

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

Tell the StoryNaked CRC

Tell the Story

Naked CRC

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

Increasing Confidence

Sensing VariablesCharacterization Tests

Pair Programming

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

Sensing Variables

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

Sensing Variables

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

Sensing Variables

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

Characterization Tests

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

Characterization Tests

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

Characterization Tests

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

You need to

Change

ATDDTDD

Refactoring

Adding Behavior

Preparing to Add

Behavior

Adding Behavior

Removing Duplication

Cleaning Technical

Debt

Prefactoring Refactoring

Remodeling

Coding

Adding Behavior

Preparing to Add

Behavior

Adding Behavior

Removing Duplication

Cleaning Technical

Debt

Prefactoring Refactoring

Remodeling

Coding

ATDD

Adding Behavior

Preparing to Add

Behavior

Adding Behavior

Removing Duplication

Cleaning Technical

Debt

Prefactoring Refactoring

Remodeling

Coding

ATDDTDD

Adding Behavior

Preparing to Add

Behavior

Adding Behavior

Removing Duplication

Cleaning Technical

Debt

Prefactoring Refactoring

Remodeling

Coding

ATDDTDD

Refactoring

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

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

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

http://www.fitnesse.org

http://www.fitnesse.org

http://www.fitnesse.org

http://www.fitnesse.org

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.

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

Red

Green

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

Red

Green

Refactor

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

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

Feather’s ApproachATDD Approach

Edit and Pray

Feather’s Approach

Identify Change Points

Feather’s Approach

Identify Change Points

Find Test Points

Feather’s Approach

Identify Change Points

Find Test Points

Break Dependencie

s

Feather’s Approach

Identify Change Points

Find Test Points

Break Dependencie

s

Write Tests

Feather’s Approach

Identify Change Points

Find Test Points

Break Dependencie

s

Write Tests

Make Changes

Feather’s Approach

Identify Change Points

Find Test Points

Break Dependencie

s

Write Tests

Make Changes

Refactor

Feather’s Approach

ATDD Approach

WriteAcceptance

Tests

ATDD Approach

WriteAcceptance

Tests WriteCharacterization

Tests

ATDD Approach

WriteAcceptance

Tests WriteCharacterization

Tests

ImplementBehavior

ATDD Approach

WriteAcceptance

Tests WriteCharacterization

Tests

ImplementBehavior

Get All Tests to Pass

ATDD Approach

WriteAcceptance

Tests WriteCharacterization

Tests

ImplementBehavior

Get All Tests to Pass

Celebrate!

ATDD Approach

WriteAcceptance

Tests WriteCharacterization

Tests

ImplementBehavior

Get All Tests to Pass

Celebrate!

ATDD Approach

WriteAcceptance

Tests WriteCharacterization

Tests

ImplementBehavior

Get All Tests to Pass

Celebrate!

ATDD Approach

WriteAcceptance

Tests WriteCharacterization

Tests

ImplementBehavior

Get All Tests to Pass

Celebrate!

ATDD Approach

Recommended